我是javascript和AngularJS的新手,想知道为什么引号内的表达式没有被评估?
<span ng-show="{{remaining()}}!==0">sometext</span>
Run Code Online (Sandbox Code Playgroud)
它只是这样打印:
<span ng-show="2!==0">sometext</span>
Run Code Online (Sandbox Code Playgroud)
无论内容如何,ng-show都不起作用.即使表达式包含在eval中,也会显示文本(和打印的表达式):
eval("{{remaining()}}!==0")
Run Code Online (Sandbox Code Playgroud)
为了这个,我在控制器中创建了一个函数:
<span ng-show="renderOrNot()">sometext</span>
Run Code Online (Sandbox Code Playgroud)
这是有效的,但我希望每次想要进行比较时都不必编写函数
我正在使用@ angular/material 2.0.0-alpha.11-3 angular-cli 1.0.0-beta.19-3 karma 1.2.0 karma-jasmine 1.0.2开发Angular2应用程序
运行它工作正常,但模板有md-icon按钮的几个测试失败,模板错误:
ERROR: 'Unhandled Promise rejection:', 'Template parse errors:
'md-icon' is not a known element:
1. If 'md-icon' is an Angular component, then verify that it is part of this module.
2. If 'md-icon' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message
Run Code Online (Sandbox Code Playgroud)
我的app.module.ts:
import { MaterialModule } from '@angular/material';
@NgModule({
declarations: [
AppComponent,
LinearProgressIndicatorComponent,
MyNewDirectiveDirective,
MyNewServiceDirective,
HeaderComponent,
MenuComponent,
WatchpanelComponent,
InputComponent
],
imports: [ …Run Code Online (Sandbox Code Playgroud) 我正在开发一个运行良好的应用程序,但Jasmine测试会抛出模板错误.由于运行应用程序有效,模板引用变量可以绑定到ngModel,但为什么在运行测试时它不起作用?我正在使用"@ angular/forms":"~2.2.3",
ERROR: 'Unhandled Promise rejection:', 'Template parse errors:
There is no directive with "exportAs" set to "ngModel" ("d="name" required pattern="^[a-zA-Z]+[\s\S]*"
[(ngModel)]="model.name" name="name" [ERROR ->]#name="ngModel" >
</div>
<div [hidden]="name.valid || name.pristine"
Run Code Online (Sandbox Code Playgroud)
我的app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { LinearProgressIndicatorComponent } from './linear-progress-indicator/linear-progress-indicator.component';
import { MyNewDirectiveDirective } from './directives/my-new-directive.directive';
import { MyNewServiceDirective } from './services/my-new-service.directive'; …Run Code Online (Sandbox Code Playgroud)