所以我有一個單選按鈕的列表,我試圖用指令中的$ watch觀看選擇的變化。我只能在第一次選擇這些元素時觸發手錶。angularjs看單選按鈕換工作只在第一選擇
我的HTML:
<p ng-repeat="(key,item) in option" style="margin-bottom:0px ">
<label>
<input type="radio" is-valid ng-model="value" selected-key="value" name="select" value="{{key}}" ng-checked="getChecked($index)"> {{item.name}}
</label>
</p>
我的指令回報:
return {
restrict: "A",
scope: {
selectedKey: '='
},
link: function(scope, elem, attrs) {
scope.$watch('selectedKey', function(newValue, oldValue, scope) {
alert('triggered')
});
}
}
我在做什麼錯?我試着只看「價值」,但看不到觸發。
預先感謝您
您可以簡單地使用'ngChange'。 https://docs.angularjs.org/api/ng/directive/ngChange你爲什麼需要自定義指令? – Satpal
雅我可以做到這一點,但後來我不得不添加另一個控制器功能,我已經有一個名爲is-valid的指令屬性用於類似的任務。我認爲我認爲寫得更好會更好。 –