2016-05-19 12 views
1

私はhtmlを持っています。htmlから変数AngularJSに変数を渡すにはどうしたらいいですか?

<div class="dashboardTr" ng-repeat="post in posts"> 
    <modal-dashboard header="Success" body="post.ID" id="success"></modal-dashboard> 
</div> 

と、このディレクティブ:

app.directive('modalDashboard', function() { 
    return { 
     restrict: 'E', 
     scope: { 
      header: '@header', 
      body: '=', 
      id: '@id' 
     }, 
     templateUrl: '/modalDashboard.html' 
    } 
}); 

ポップアップの新しいHTMLは次のとおりです。

<div class="modal-content"> 
    <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal">&times;</button> 
       <h4 class="modal-title">{{ header }}</h4> 
    </div> 
    <div class="modal-body"> 
       <p>{{ body }}</p> 
    </div> 
</div> 

それは動作しません。私はこれを持っています。 bodyプロパティに文字列を渡すと、それが動作します。どうしたの? 別の指令の中にあります。それは問題だろうか? ありがとうございました!

+0

を使用すると、ランダムな単語とはどういう意味ですか?ランダムな言葉をどこに渡していますか? – Avinash

+0

@Avinash A string – Ary

+0

'body'と' header'の場合はDOMと競合していると思うので、それを変更してみてください。 – Hearty

答えて

-1

これは動作するはずです:

app.directive('modalDashboard', function() { 
return { 
    restrict: 'E', 
    scope: { 
     header: '@header', 
     body: '=body', // <-- make sure to modify this to evaluate body attribute 
     id: '@id' 
    }, 
    templateUrl: '/modalDashboard.html' 
} 
}); 
+0

いいえ、私はこれを最初に試しました。最初のhtmlは別の指令の中にあります。それは問題だろうか? – Ary

+0

はい、それはほとんどの理由の –

+0

ここで動作することを確認する作業デモを確認してください: http://jsbin.com/levuhabeji/edit?html,output –

関連する問題