[英]Why isn't my ng-controller being called?
I'm trying to follow a tutorial to familiarize myself with Angular. 我正在尝试按照一个教程来熟悉Angular。 So if this questions is incredibly simple, I apologize in advance. 因此,如果这个问题非常简单,我先向您道歉。 In my index.html
, I'm trying to call one of the controllers to test out how Angular calls certain things. 在我的index.html
,我试图调用一个控制器以测试Angular如何调用某些东西。
In the code, I have <div ng-controller="listCtrl">
. 在代码中,我有<div ng-controller="listCtrl">
。 However, something as simple as {{3+5}}
isn't being evaluated and being printed to the page as is. 但是,像{{3+5}}
这样简单的事情并未得到评估,并不会按原样打印到页面上。 I've tried messing around with the ng
attribute and when I have something like 我试图弄乱ng
属性,当我有类似的东西
<div ng-app="">
{{3+5}}
</div>
it will work and print out 8. I was wondering if someone could take a look at the code (posted below) and tell me what I'm doing wrong. 它可以正常工作并打印出来。8.我想知道是否有人可以看一下下面的代码并告诉我我做错了什么。
My index.html
file: 我的index.html
文件:
<!doctype html>
<html lang="en" ng-app="turtleFacts">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Heading</h1>
<h3>Heading3
<strong>QUIZ</strong>
</h3>
</div>
<div ng-controller="listCtrl">
{{dummyData}}
</div>
</div>
<!-- My application scripts -->
<script src="js/app.js"></script>
<script src="js/controllers/list.js"></script>
</body>
</html>
My list.js
: 我的list.js
:
(function(){
angular
.module("turtleFacts")
.controller("listCtrl", ListController);
function ListController($scope) {
$scope.dummyData = "hello world";
}
})
And my app.js
: 和我的app.js
:
(function() {
angular
.module("turtleFacts", []);
})();
My folder structure looks like: 我的文件夹结构如下:
Project
|
+-- css
|
+-- js
| |
| +-- controllers
| | |
| | +-- list.js
| |
| +-- app.js
|
+-- index.html
It's my assumption that the page should have "Hello World" but all I'm getting is {{dummyData}}
. 我以为该页面应该有“ Hello World”,但我得到的只是{{dummyData}}
。 Please let me know if there's any other information I can provide that you may need. 如果需要我提供的其他信息,请告诉我。 Thanks! 谢谢!
In the list.js
, you forgot to add ();
在list.js
,您忘记添加();
list.js
at the end of your IIFE :) 在您的IIFE结尾:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.