2017-12-24 3 views
0

パラメータ:requestsとcurrentUserを取得する必要がある独自のディレクティブを作成しようとしています。2番目の変数をisoloatedスコープに渡すことはできませんAngularJS

requestsパラメータが正常にditectiveに渡されましたが、currentUserは渡されません。

currentUserは、$ rootScopeのapp.runで定義されています。

ディレクティブ:

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

app.run:

私はCurrentUserには 'dashboard.html'

コードでアクセス可能であることに注意しなければならないことはこれです

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

dashboard.html(関連部分のみ):

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

何が問題であり、どのように修正することができますか?

答えて

1

でダッシュ表現として扱われているので

+0

は疑問符が何を意味するのかを下回るような

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

変更あなたのスコープバインディング? – Ori

0

あなたはそれを参照しているので、それは蛇のケースに入れ、HTMLであるべきとき同棲らくだの:そう同様

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

。キャメルケースが正しいバインディングを使用していないの問題である可能性が角度指令入力

0
が、それは間違いなく

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

を動作しますが、以下のようなHTMLコードを変更し

し、 currentUser要素もHTMLでは間違っています。それは下に生きているはずです。

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

関連する問題