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'。 –
我有单独的指令:'