I work with angular and try to disable a button if a value from my scope is 'true'. I saw the ng-disabled
which seems to be perfect but I don't know why it doesn't work...
我使用angular并尝试禁用一个按钮,如果我的范围中的值为'true'。我看到ng-disabled看起来很完美,但我不知道为什么它不起作用......
Here is my HTML:
这是我的HTML:
<div ng-controller="MyCtrl">
<h4>{{ building.isBuildable }}</h4>
<button ng-click='build(building.id)'
class="btn btn-primary"
ng-disabled="!build.isBuildable">
Build
</button>
</div>
And my angular:
我的角度:
var myApp = angular.module('myApp',[]);
myApp.factory('Colony', function () {
'use strict';
return {
isBuildable: function () {
return true;
//return false;
}
};
});
myApp.controller('MyCtrl', ['$scope', 'Colony', function ($scope, Colony) {
'use strict';
var building = {
name: 'Building Name',
isBuildable: null
};
$scope.building = building;
$scope.building.isBuildable = Colony.isBuildable();
$scope.build = function (id) {
};
}]);
http://jsfiddle.net/xz7arL0s/1/
http://jsfiddle.net/xz7arL0s/1/
As you can see in the jsfiddle, it's always disabled even when isBuildable
is true. What am I missing here?
正如您在jsfiddle中看到的那样,即使isBuildable为true,它也始终处于禁用状态。我在这里想念的是什么?
1 个解决方案
#1
4
You have a typo, you're referring to build instead of building in the ng-disabled
binding.
你有一个拼写错误,你指的是构建而不是在ng-disabled绑定中构建。
Update your code to:
将您的代码更新为:
<div ng-controller="MyCtrl">
<h4>{{ building.isBuildable }}</h4>
<button ng-click='build(building.id)'
class="btn btn-primary"
ng-disabled="!building.isBuildable">
Build
</button>
</div>
I edited this also on the Fiddle.
我也在小提琴上编辑了这个。
#1
4
You have a typo, you're referring to build instead of building in the ng-disabled
binding.
你有一个拼写错误,你指的是构建而不是在ng-disabled绑定中构建。
Update your code to:
将您的代码更新为:
<div ng-controller="MyCtrl">
<h4>{{ building.isBuildable }}</h4>
<button ng-click='build(building.id)'
class="btn btn-primary"
ng-disabled="!building.isBuildable">
Build
</button>
</div>
I edited this also on the Fiddle.
我也在小提琴上编辑了这个。