【问题标题】:Trying to display scope in html - angularJS/ionic试图在 html 中显示范围 - angularJS/ionic
【发布时间】:2017-11-11 07:16:53
【问题描述】:

尝试在 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> 

【问题讨论】:

  • 你让它工作了吗? :)

标签: javascript html angularjs ionic-framework angularjs-scope


【解决方案1】:

欢迎来到 SO。你的代码基本不错,但是有两个问题:

  1. ion-header 标签应该在body 元素内
  2. 我假设您只是在此文件中包含 angular.min.js 用于测试,因此您不需要花哨的东西。但是脚本需要以正确的顺序加载。我会将它们放在结束 &lt;/body&gt; 标记之前,并切换顺序以便 Angular 在您的控制器之前加载。

当我change this in your example, it seems to work。 Ionic 不包含在任何地方,因此您当然不会获得样式,但会呈现列表。

【讨论】:

  • 所以我更改了它,但仍然没有显示任何内容。有没有办法可以把那个sn-p的代码发给我?
猜你喜欢
  • 2017-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多