Skip to content

Instantly share code, notes, and snippets.

@Sennahoi
Created November 14, 2014 10:16
Show Gist options
  • Save Sennahoi/1612771372f13728f4ba to your computer and use it in GitHub Desktop.
Save Sennahoi/1612771372f13728f4ba to your computer and use it in GitHub Desktop.
Examples of angular bindings
<ul class="list">
<li ng-repeat="location in locations">
<a href="#">{{location.id}}. {{location.name}}</a>
</li>
</ul>
<map locations='locations'></map>
// 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