【发布时间】:2016-01-27 10:56:04
【问题描述】:
在我的主视图中,我注入了一个组件,在初始加载时,它会显示正确的整数,但如果我稍后在主视图中更新该值,则附加到函数的控制台日志消息会显示正确的整数,但实际html 值不会更新。这是怎么回事?
main.js:
@Component({
selector: 'step-one',
directives: [priceBox],
templateUrl: 'step-one/step-one.html'
})
export class stepOne {
constructor(@Inject(Router) router, @Inject(Http) http, @Inject(RouteParams) params, @Inject(priceBox) pbox) {
let cid = parseInt(params.get('country'));
pbox.price = 200;
...
price-box.js
import {Component} from 'angular2/core';
@Component({
selector: 'price-box',
template: `
<div>
<h1>PRICEBOX</h1>
<p>{{totalPrice}}</p>
</div>
`
})
export class priceBox {
constructor() {
this.totalPrice = '130';
}
set price(val){
this.totalPrice = val;
console.log('SET price box: price = ' + this.totalPrice);
}
}
所以重申一下:
在页面加载时,我的价格框元素显示价格为 130...当我尝试通过 pbox.price = 200 设置新值时 该值保持在 130 但我收到控制台日志消息说SET price box: price = 200
谢谢!
【问题讨论】:
标签: angular angular2-template angular2-directives