templates - Decide when to 'templateUrl' of AngularJS directive in the link function -


is possible decide whether use templateurl parameter in link function of angularjs directive?

suppose have following directive:

app.directive('sitesandimprovements', function() {     return {         restrict: 'e',         replace:true,         templateurl: '<path-to-file>/site-and-improvments.html',         link: function (scope, elem, attrs) {             scope.testclick = function() {                 var myscope = scope;                 //debugger;             }             scope.constructioncompleteclick = function () {                 if (scope.construction_complete == 'yes') {                     scope.hold_back = '';                     scope.percent_complete = 100;                 } else                 if (scope.construction_complete == 'no') {                     scope.hold_back = '1';                     if (scope.percent_complete == 100) {                         scope.percent_complete = '';                     }                 }             }             scope.calctotal = function () {                 var total;                 total = (scope.main || 0) + (scope.second || 0) + (scope.third || 0) + (scope.fourth || 0);                 scope.total = total || null;             }         }     }  }) 

i want control whether use or not use templateurl , replace parameters in link() function.

this because implemented directive in 10+ places without using templateurl , want start using feature, don't want make changes existing , working code.

is possible , how?

tarek

i don't think can in link, believe can turn templateurl function can return different values directive.

try doing templateurl:

templateurl: function() {     if (somecondition) {         return '<path-to-file>/site-and-improvments.html';     } else {         return null;     } }, 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -