1
我試圖做一個指令,插入輸入後(用指令標記)的元素,但也更新來自插入元素的輸入。AngularJS:更新模型傳遞給指令
angular.module('afterDir', [])
.directive('after', function ($compile) {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
scope.clickHandler = function (index) {
console.log(index);
ngModel.$setViewValue("something");
}
var content = angular.element('<ul><li ng-click="clickHandler()">after</li><li ng-click="clickHandler()">after too</li></ul>');
content.insertAfter(element);
$compile(content)(scope);
}
}
});
點擊處理程序觸發但模型不更新,是否還有其他需要調用來更新模型?謝謝!
非常感謝! – kreek