javascript - Directive Parameters Nested Controller Simple Example -


here code

app.directive('hello', function() {     return {         restrict: "e",         templateurl: "/angular/modules/selector.html",         controller: function () {           this.message = [want attribute message here]         }     }; }); 

and markup

<hello message="hello world instance 1"></hello>  <hello message="hello world instance 2"></hello> 

finally, question

how can attribute controller instance each hello element?

binding datasource attribute

<hello ... datasource="/jsondata.json"></hello>  <hello ... datasource="/otherjsondata.json"></hello> 

more controller code

$http.get($attrs.datasource).success(function (data) { ... });\ 

the datasource shared need 2 separate instances.

thanks, blackhole advice!

working code

i can attributes explained. did notice attributes strangely change lower case fine me. scope: { } trick creating isolated instances.

app.directive('selector', function () {     return {         restrict: "e",         templateurl: "/angular/modules/selector.html",         scope : {},         controller:  function ($http, $scope, $element, $attrs) {            ...             this.displayfield = $attrs.displayfield;            ...             $http.get($attrs.datasource).success(function (data) {             ...             });         },         controlleras : "selector"     }; }); 

the markup

nothing changed except new attributes added instead of message.

<selector id="selector1" datasource="/company/companylistviewdata2"     displayfield="name"></selector> <selector id="selector2" datasource="/employee/simpleemployeelistviewdata"     displayfield="lastnamefirstname"></selector> 

thanks again, works great!


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -