最近,我不得不讓一個Input元素同時使用ng-disabled和一個自定義指令,它們使用隔離範圍來評估表達式,就像ng-disabled在做什麼一樣,自定義指令工作正常,但ng-disabled沒有,因爲它只評估隔離範圍內的表達式。如何讓ng禁用的指令在隔離範圍內工作
自定義指令非常簡單,如:
angular
.module('directives', [])
.directive('conditionalAutofocus', function() {
return {
restrict:'A',
scope:{
condition:'&conditionalAutofocus'
},
link:function (scope, element, attrs) {
if (scope.condition()) {
attrs.$set('autofocus','true');
}
}
}
});
而頁面的樣子:
<input name="pin"
ng-model="pin"
type="password"
required
ng-disabled="names == null"
conditional-autofocus="names != null" />
有人已經爲這個問題的解決方案?
在此先感謝! 雅尼
你能爲你的問題創建一個jsfiddle嗎? –
誰在低估答案?對於基督人而言,低估是因爲不安全和嚴重的概念錯誤......至少和其他人一樣,我知道嚴重的概念錯誤...... – BradChesney79