2017-11-10 131 views
0

試圖在html中顯示範圍 - angularJS/ionic 嘗試在我的網頁上顯示標題,但沒有顯示任何內容。我對角和離子框架相當陌生。如果任何人都可以指出我做錯了什麼,這將有助於一噸!試圖在html中顯示範圍 - angularJS/ionic

這裏是我的控制器JS:

angular.module('MyApp', []) 

.controller('TodoCtrls', function($scope) { 


    $scope.tasks = [ 
    { title: 'Collect coins' }, 
    { title: 'Eat mushrooms' }, 
    { title: 'Get high enough to grab the flag' }, 
    { title: 'Find the Princess' } 
    ]; 
}) 

而且我的html:

<html ng-app="MyApp"> 

<ion-header> 
    <ion-navbar> 
    <ion-title>Courses</ion-title> 
     <h1 class="title">Todo</h1> 
    </ion-navbar> 
</ion-header> 

<script src="TodoCtrl.js"></script> 

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 



<body ng-app="MyApp" ng-controller="TodoCtrls"> 
    <ion-content> 
    <ion-list> 
     <ion-item ng-repeat="task in tasks"> 
     <h1>{{task.title}}</h1><br> 
     </ion-item> 
    </ion-list> 
    </ion-content> 
</body> 

</html> 
+0

你得到它的工作? :) –

回答

0

歡迎SO。您的代碼基本上是好的,但有兩個問題:

  1. ion-header標籤應該是body元素
  2. 我假設你只是包括在此文件中進行測試的angular.min.js內,所以你不需要一些花哨的東西。但腳本需要按照正確的順序加載。我會在關閉</body>標籤之前放置它們,然後切換訂單,以便在控制器之前加載Angular。

當我I change this in your example, it seems to work。離子不包括在任何地方,所以你當然不會得到樣式,但是列表被渲染。

+0

所以我改變了它,我仍然沒有顯示任何內容。有沒有辦法可以向我發送代碼片段? –

+0

當然@KateWatkins http://embed.plnkr.co/AdJY6wBCQszF6HRgOtyz/ –