输入值正确绑定到模型(在这种情况下为0,我尝试过其他数字并且alwyas正确初始化),但ng-change函数永远不会触发(我尝试使用ng-blur代替ng-change,它也不会触发......)
HTML(jade):
div.app_area(ng-controller="AppCtrl")
div.app_wrapper
label.inline Value
span.glyphicon.glyphicon-random.convert_icon
.input-group
input.form-control(type="text", ng-model='usd', ng-blur='convert_to_btc()', placeholder="USD")
span.input-group-addon.glyphicon.glyphicon-usd
.input-group
input.form-control(type="text", ng-model='btc', ng-blur='convert_to_usd()', placeholder="BTC (Approx.)")
span.input-group-addon.glyphicon.glyphicon-bitcoin
控制器:
app.controller("AppCtrl", function AppCtrl($scope, $http, $interval ) {
$scope.usd = 0;
$scope.btc = 0;
some_func = function() {
//do something
}
convert_to_usd = function() {
alert("hallo");
$scope.usd = $scope.btc * $scope.bitfinex_price;
}
convert_to_btc = function() {
alert("hello");
$scope.btc = $scope.usd / $scope.bitfinex_price;
}