Created
November 14, 2014 10:16
-
-
Save Sennahoi/1612771372f13728f4ba to your computer and use it in GitHub Desktop.
Examples of angular bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="list"> | |
<li ng-repeat="location in locations"> | |
<a href="#">{{location.id}}. {{location.name}}</a> | |
</li> | |
</ul> | |
<map locations='locations'></map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// scope.location = { id : 123 }; | |
// Source: http://stackoverflow.com/questions/21667613 | |
app.directive('map', function() { | |
return { | |
restrict: 'E', | |
replace: true, | |
template: '<div></div>', | |
scope: { | |
// creates a scope variable in your directive | |
// called `locations` bound to whatever was passed | |
// in via the `locations` attribute in the DOM | |
locations: '=locations' | |
}, | |
link: function(scope, element, attrs) { | |
scope.$watch('locations', function(locations) { | |
angular.forEach(locations, function(location, key) { | |
// do something | |
}); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment