2017-10-21 87 views
0

我不明白爲什麼通過@observable這個「屬性改變」不起作用,stringValueChanged()方法沒有被調用。我在這裏錯過了什麼? (整個結合不在這裏工作。)aurelia:binding和@observable不工作

貨幣control.ts

import { bindable, observable } from 'aurelia-framework'; 

export class CurrencyControl { 

    @bindable 
    value: number; 

    @observable 
    stringValue: string; 

    constructor() { 
    } 

    valueChanged(newValue: number, oldValue: number) { 
     alert('value changed'); 
    } 

    stringValueChanged(newValue: string, oldValue: string) { 
     alert('stringValueChanged changed'); 
    } 
} 

貨幣control.html

<template> 

    <require from="./currency-control.css"></require> 

    <div class="input-group"> 
     <div class="input-group-addon">&euro;</div> 
     <input type="text" maxlength="5" pattern="\d*" class="form-control" value.bind="stringValue" /> 
    </div> 

</template> 

回答

0

我的錯!在使用我所需要的CurrencyControl的HTML中CurrencyControl組件:

<template> 
    <require from="../currency-control/currency-control.html"></require> 

,而不是組件:

<template> 
    <require from="../currency-control/currency-control"></require>