i'm trying update element directive on blur view gets changed, not model.
app.directive('mydirective', function() { return { require: 'ngmodel', link: function(scope, element, attrs, ctrl) { element.bind('blur', function(e) { element[0].value = 'new val'; }); } }; });
i've created simple plunk highlighting issue: https://plnkr.co/edit/yicendshnagapxxp7yrf?p=preview
lots of people seem have problem , there lots of advice how change specific model using function on scope. want able drop directive onto input hardcoding model change isn't going work here.
i've tried using $apply discussed here that's not working either. http://nathanleclaire.com/blog/2014/01/31/banging-your-head-against-an-angularjs-issue-try-this/. missing?
thanks,
try (plunker):
var app = angular.module('myapp', []); app.controller('myctrl', ['$scope', function($scope) { $scope.myval = 'demo'; }]); app.directive('mydirective', function() { return { require: '^ngmodel', scope:{ngmodel:'='}, link: function(scope, element, attrs, ctrl) { element.bind('blur', function(e) { scope.ngmodel='new val'; scope.$apply(); }); } }; });
Comments
Post a Comment