2014-10-30 34 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

不知道你到底想要做什麼...爲什麼把html放在腳本標記中? – user2717954 2014-10-30 09:09:26

回答

0

你的卡在控制器的陣列,所以你需要通過使用迭代他們ng-repeat

<script id="modal-2.html" type="text/ng-template"> 
<div class="modal transparent"> 
<div class="card" ng-repeat="card in cardss"> 
<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> 

在您的例子中,數組是缺少左方括號這樣的陣列將是這樣的:

$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

如果我不想重複內容,該怎麼辦?我只想從卡內的數組中獲得1個標題和1個細節? – Garrett 2014-10-30 10:13:36

+0

然後你需要像這樣cardss [0] .title訪問它,其中0是你想要訪問的數組中元素的索引 – V31 2014-10-30 11:08:36

+0

謝謝...你能提供一個例子嗎? – Garrett 2014-10-30 11:18:14

0

沒有什麼特別的WRT裏面使用部分模板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例子。

相關問題