javascript - Why overridden `controller.$render` is not getting called? -
have @ code @ plnkr.co. in link
function of directive
, controller.$render()
called worked fine. problem when override controller.$render
function not run. console.log('overridden $render function called');
not appear in console.
script.js
is:
var app = angular.module('myapp', []); app.directive('test', function () { return { require: '?ngmodel', link: function ($scope, $element, $attr, controller) { if (!controller) { console.log("controller of ngmodel not found"); return; } else { console.log("controller of ngmodel found"); controller.$setviewvalue('qwerty'); //controller.$render(); controller.$render = function(){ console.log('overridden $render function called'); } } } }; });
index.html
is:
<!doctype html> <html ng-app="myapp"> <head> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script> <script src="script.js"></script> </head> <body> <div>todo write content </div> <input test type="text" ng-model="name" > <h1>name: {{name}}</h1> </body> </html>
try calling controller.$render()
right after override it:
var app = angular.module('myapp', []); app.directive('test', function () { return { require: '?ngmodel', link: function ($scope, $element, $attr, controller) { if (!controller) { console.log("controller of ngmodel not found"); return; } else { console.log("controller of ngmodel found"); controller.$setviewvalue('qwerty'); //controller.$render(); controller.$render = function(){ console.log('overridden $render function called'); } controller.$render(); } } }; });
Comments
Post a Comment