0

I want to pass the scope variables defined in the 'MapCtrl' to the 'mapCanvas' directive. As the code stands the console.log returns undefined. Does anyone know how I can pass the variables from my controller to my directive? Thanks.

angular.module('Ski').controller('MapCtrl', function($scope, $http) {
  'use strict';


  $http.get('https://quiet-journey-8066.herokuapp.com/mountains/5').success(function(response) {
      console.log(response);
      $scope.mountain = response.name;
      $scope.lat = response.latitude;
      $scope.lng = response.longitude;
    });


});



angular.module('Ski').directive('mapCanvas', function() {

  return {

    link: function(scope, element) {
        console.log(scope.lat)
        console.log(scope.lng)
        console.log(scope.mountain)
      };
   }
}
Billy
  • 823
  • 3
  • 12
  • 28
  • possible duplicate of [When writing a directive, how do I decide if a need no new scope, a new child scope, or a new isolate scope?](http://stackoverflow.com/questions/14914213/when-writing-a-directive-how-do-i-decide-if-a-need-no-new-scope-a-new-child-sc) – j.wittwer Dec 15 '14 at 00:38
  • 1
    Pass scope variables from your controller to your directive through your directives attributes. For your directive declare an isolated scope : use @ binding if they are simple strings, use = binding if you're binding a model – Michael Kang Dec 15 '14 at 00:55
  • use scope.$broadcast on your controller and then use the property inside your controller and isolate it on your directive and then scope.$watch your_isolated_scope inside your directive. this is another case if you want to update if data changes again :) – Victor Soto Dec 15 '14 at 07:13

0 Answers0