javascript - AngularJs share $scope between controller and controller -


i can't understand why can't access $scope properties directive, documentation says directives doesn't create new scopes, why can't acess $scope properties?

at app.js

'use strict';  var climbingapp = angular.module('climbingapp', []);  climbingapp.controller('ctrl', function($scope) {      $scope.initlocation = {         lat: -54.798112,         lng: -68.303375     }; 

at google-map.js

'use strict';  climbingapp.directive('gmap', function() {         return {             restrict: 'e',             replace: true,             template: '<div id="map-canvas"></div>',             link: function(scope, ielement, attrs) {                 console.log(scope.initlocation);             },         }      }) 

at index.html

  <html ng-app="climbingapp">      <body>     <gmap></gmap>      </body>     </html>  <script src="//code.angularjs.org/1.2.0-rc.2/angular.min.js"></script>  <script src="app/app.js"></script> <script src="app/dependencies/google-maps.js"></script> 

the console.log returns undefined.

you have associate controller view (if use ngroute) or element using ng-controller. this:

<body ng-controller="ctrl">...</body> 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -