AngularJS [SOLVED]: Cannot pass second variable to isoloated scope AngularJS

AngularJS [SOLVED]: Cannot pass second variable to isoloated scope AngularJS

Home Forums Frameworks AngularJS tutorials AngularJS [SOLVED]: Cannot pass second variable to isoloated scope AngularJS

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #246225

    Cloudy Point
    Keymaster

    QuestionQuestion

    I am trying to create my own directive that has to get to parameters: requests and currentUser.

    The requests parameter succesfully passed to the ditective but the currentUser is not.

    The currentUser is defiend in app.run in the $rootScope.

    I have to note that the currentUser is accessible in the ‘dashboard.html’

    The code is this:

    The directive:

    app.directive('requestsTableForBuyer', function() {
      return {
        'restrict': 'AE',
        'templateUrl': '../directives/requestsTables/requestsTableForBuyer.html',
        'scope': {
          requests: "=",
          currentUser: "="
        },
        'controller': function($scope, $timeout, toaster) {
          console.log($scope.currentUser);
        }
    });
    

    The app.run:

    app.run(function($rootScope) {
      $rootScope.currentUser = "ori";
    });
    

    The dashboard.html (just the relevant part):

    <requests-table-for-buyer requests="requests" currentUser="currentUser"></requests-table-for-buyer>
    

    What might be the problem and how it can be fixed?

    #246226

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    Could be the problem of not using the correct bindings and also currentUser element is wrong in the HTML. It should be live below.

    <requests-table-for-buyer requests="requests" current-user="currentUser"></requests-table-for-buyer>

    Change your scopes bindings like below


    app.directive('requestsTableForBuyer', function() {
    return {
    'restrict': 'AE',
    'templateUrl': '../directives/requestsTables/requestsTableForBuyer.html',
    'scope': {
    requests: "=",
    currentUser: "=?"
    },
    'controller': function($scope, $timeout, toaster) {
    console.log($scope.currentUser);
    }
    });

    Source: https://stackoverflow.com/questions/47960406/cannot-pass-second-variable-to-isoloated-scope-angularjs
    Author: Osanda Wedamulla
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.