0
我有這樣的指令:
app.directive('selectedForm', function(MainService) {
return {
scope: {
formName: '=currentForm'
},
restrict: 'E',
link: function($scope, iElm, iAttrs, controller) {
$scope.$watch('formName', function(oldV, newV) {
console.log(iElm);
if (someCondition) {
MainService.getForm($scope.formName).then(function(re) {
iElm.html(re);
});
}
});
}
};
});
但是,問題是我不能觀看更改。我在DOM中有一個<select>
元素,它改變了currentForm
的使用值ngModel
。但是,即使我選擇了一個選項,watch
函數也不起作用。我錯過了什麼嗎?
所以,我可以不看改變'$ scope' ...? –
你可以。我只是說,你不能像在控制器中一樣使用'$ watch'。 –
我有單獨的指令:'