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:
countryinner scope variable of item in array ofcountriescountry-dirdirective (which has normalized form ofcountrydir)."=countrydir"two-way bindingcountry-dirattribute (which happens directive itself, doesn't have be)countryobjinternal isolate scope property boundcountryobject, in case want internal name different attribute. otherwise, have been shortenedcountrydir: "=".
Comments
Post a Comment