Angularjs-ng禁用的默认值
我有一个具有此属性的按钮:Angularjs-ng禁用的默认值,angularjs,Angularjs,我有一个具有此属性的按钮:ng disabled=“ProductionBtnDisabled” 当angular呈现html时,ProductionBtnDisabled的值未定义,并且在启动控制器后,ProductionBtnDisabled具有正确的值 因此,首先,ng disabled没有被禁用,因为在javascript/angular中undefined=false。这对我来说是个问题。我希望默认值为true 有人有什么建议来处理这个问题吗 使用ng斗篷怎么样?这对我不起作用。我不介
ng disabled=“ProductionBtnDisabled”
当angular呈现html时,ProductionBtnDisabled
的值未定义,并且在启动控制器后,ProductionBtnDisabled
具有正确的值
因此,首先,ng disabled
没有被禁用,因为在javascript/angular中undefined=false
。这对我来说是个问题。我希望默认值为true
有人有什么建议来处理这个问题吗
使用ng斗篷怎么样?这对我不起作用。我不介意在显示范围之前隐藏按钮
谢谢 我认为ngDisabled没有默认设置。如果您需要一个全局解决方案,可以尝试使用该指令
.directive('specialDisabled',function() {
return {
restrict: 'A',
scope:{specialDisabled: '='},
link: function(scope, element, attrs) {
scope.$watch(function(){return scope.specialDisabled}, function(){
// set disabled attribute here
element[0].disabled = !scope.specialDisabled;
});
}
}
});
然后,您可以在任何地方调用specialDisabled指令
<input type="checkbox" ng-model="chk">
<button special-disabled="chk">My Button</button>
我的纽扣
ng disabled=“ProductionBtnDisabled | | ProductionBtnDisabled===未定义”。这不好。我想要一个全局解决方案,而不是在每个按钮上都这样做。你能展示一些代码吗?如何在控制器中设置该值?显示问题的代码示例将是完美的。HTML:Process Now Controller:tpObj.ProductionBtnDisabled=tpObj.isProductionDisabled();tpObj.isProductionDisabled()还有一个Ajax调用。