2014-10-29 37 views
0

如何獲取腳本標記內部的角度表達式......我對此很新,需要幫助? 這裏是我的Java腳本代碼的例子:在腳本標記內部工作的角度表達式

<script id="modal-2.html" type="text/ng-template"> 
<div class="modal transparent"> 
<div class="card"> 
<i class="icon ion-ios7-close close-modal" ng-click="closeModal(2)"></i> 
<div class="item item-divider"> 
{{card.title}} 
</div> 
<div class="item item-text-wrap"> 
{{card.details}} 
</div> 
</div> 
</div> 
</script> 

這裏是我的數組的一個例子:

.controller('TodoCtrl', function($scope, $ionicPopup, $timeout, $ionicModal, $ionicSideMenuDelegate) { 

    $scope.cardss = 
    {id:1, title:'Frank', src:'img/Frank.png',details:'This will be the products description!'}, 
    {id:2, title:'Generali', src:'img/Generali.png',details:'This will be the products description!'}, 
    {id:3, title:'John Lewis', src:'img/JohnLewis.png',details:'This will be the products description!'}, 
    ]; 

回答

0

下面是一個例子,你如何使用您的模板:

<div ng-include src="'modal-2.html'"></div> 

或使用按鈕來配合使用:

<button ng-click="currentTpl='modal-2.html'">Show Modal</button> 
<div ng-include src="currentTpl"></div> 

模板中的表達式與通常的一樣工作。
這是一個example

+0

爲什麼downvote?這是一個工作示例 – friedi 2014-10-29 15:27:03

1

在部分模板中沒有什麼特別的使用AngularJS表達式。

前面已經說了你的模型實際上是陣列 - 所以你必須通過使用ng-repeat這樣的項目迭代:

<ul> 
    <li ng-repeat="card in cards"> 
     Card id: {{card.id}} 
     Card title: {{card.title}} 
     Card details: {{card.details}} 
    </li> 
</ul> 

請參閱工作JSFiddle例子。