请参考此扑通。
它是基于角快速启动样例,这里模板是调用一个函数。
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<h1>Hello {{name}}</h1>{{print()}}`
})
export class AppComponent {
name = 'Angular';
public print() {
console.log(`Called`);
return "Hello";
}
}打印函数被调用4次,但UI只显示了3次。(参见第二次重击)。在第二次重击中,角确实抛出错误表达式在检查后发生了变化。
如果我启用了生产模式,它只会被调用两次。
我的问题是:
发布于 2017-01-14 09:42:38
不建议在function中使用Angular2 bindings/interpolation.
您应该使用变量,如下所示,
template: `<h1>Hello {{name}}</h1>{{myVar}}`
name:string='';
constructor(){
this.print();
}
public print():string {
console.log(`Called`);
this.name = "Hello";
}https://stackoverflow.com/questions/41648577
复制相似问题