angularjs with Leafletjs

前端 未结 4 1629
独厮守ぢ
独厮守ぢ 2020-12-25 09:55

Following directie code is from http://jsfiddle.net/M6RPn/26/ I want to get a json feed that has many lat and long.. I can get a json with $resource or $http in Angular easi

4条回答
  •  [愿得一人]
    2020-12-25 10:43

    Directives and mvc in angularJs are different technologies. Directives are usually executed when the page loads. Directives are more for working on/with html and xml. Once you have JSON, then its best to use the mvc framework to do work.

    After the page has rendered, to apply directives you often need to do $scope.$apply() or $compile to register the change on the page.

    Either way, the best way to get a service into a directive is by using the dependency injection framework.

    I noticed the scope:true, or scope:{} was missing from your directive. This has a big impact on how well the directive plays with parent controllers.

    app.directive('mapThingy',['mapSvc',function(mapSvc){
      //directive code here.
    
    }]);
    
    app.service('mapSvc',['$http',function($http){
     //svc work here.
    }])
    

    Directives are applied by camelCase matching. I would avoid using or because of an issue with IE. Alternative would be

提交回复
热议问题