Skip to content

Instantly share code, notes, and snippets.

@Sennahoi
Created November 14, 2014 10:16
Show Gist options
  • Select an option

  • Save Sennahoi/1612771372f13728f4ba to your computer and use it in GitHub Desktop.

Select an option

Save Sennahoi/1612771372f13728f4ba to your computer and use it in GitHub Desktop.

Revisions

  1. Sennahoi created this gist Nov 14, 2014.
    6 changes: 6 additions & 0 deletions example1.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <ul class="list">
    <li ng-repeat="location in locations">
    <a href="#">{{location.id}}. {{location.name}}</a>
    </li>
    </ul>
    <map locations='locations'></map>
    23 changes: 23 additions & 0 deletions example1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    // 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
    });
    });
    }
    };
    });