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
Post a Comment