javascript - Get confused by the scope in angularJS -


i'm learning angulajs video introduction angular.js in 50 examples , it's awesome i'm confused since #46. we, say, want nation's information json file , display it, , have directive definition:

countryapp.directive('country', function () {     return {         scope: {             country: '=country'         },         restrict: 'a',         templateurl: 'country.html'     }; }); 

and invoke directive country in html:

<ul>     <li ng-repeat="country in countries" country="country"></li> </ul> 

my question is: exact meaning of 4 different nouns "country" is? first 2 in directive scope(country: '=country' ), last 2 in html(country="country"). understand first 1 variable definition in directive, should change name such dir_country, can't work !

here's example different:

<li ng-repeat="country in countries" country-dir="country"> 
.directive("countrydir", function(){   return {     scope: {       countryobj: "=countrydir"     },     template: "<span>{{countryobj.name}}</span>",     link: function(scope){       console.log(scope.countryobj); // bound country object     }   }; }); 

here:

  • country inner scope variable of item in array of countries
  • country-dir directive (which has normalized form of countrydir).
  • "=countrydir" two-way binding country-dir attribute (which happens directive itself, doesn't have be)
  • countryobj internal isolate scope property bound country object, in case want internal name different attribute. otherwise, have been shortened countrydir: "=".

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -