[英]Why can't I get Angularjs to work?
I am trying angularjs for the first time and I am having trouble getting it to actually work..I think. 我是第一次尝试angularjs,但是我很难让它真正起作用。
I am doing the exercises on a website and when I run it on the website it works, but when I try to follow along and write it myself in my own files I can't get it to work. 我正在网站上进行练习,当我在网站上运行它时,它可以工作,但是当我尝试按照自己的方式将其写在自己的文件中时,则无法正常工作。
For example: when I type this "{{store.product.name}}" it prints exactly that including the braces, but on the site it prints out "Azurite" 例如:当我键入此“ {{store.product.name}}”时,它会精确打印出包含花括号的内容,但在网站上它会打印出“ Azurite”
my code: 我的代码:
index.html index.html
<!DOCTYPE html>
<html ng-app="test">
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<script src="app.js"></script>
<script src="angular.min.js"></script>
</head>
<body ng-controller="StoreController as store">
<div>
<h3>{{store.product.name}}</h3>
<h3>{{store.product.price}</h3>
</div>
</body>
</html>
app.js app.js
(function(){
var gem = { name: 'Azurite', price: 2.95 };
var app = angular.module('gemStore', []);
app.controller('StoreController', function(){
this.product = gem;
});
})();
You shuld close the double curly brace 你应该合上双花括号
You have 你有
<h3>{{store.product.price}</h3>
Should be 应该
<h3>{{store.product.price}}</h3>
Regards 问候
Your app name is incorrect. 您的应用名称不正确。
<html ng-app="gemStore"> </html>
gemStore
is the name for your app not test
. gemStore
是您的应用未test
的名称。
when you working with angular app . 当您使用角度应用程序。
You need angularJs script first and others should follow. 您首先需要angularJs脚本,然后应该其他脚本。
<!DOCTYPE html>
<html ng-app="gemStore">
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<script src="angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="StoreController as store">
<div>
<h3>{{store.product.name}}</h3>
<h3>{{store.product.price}</h3>
</div>
</body>
</html>
let me know if you need any help. 让我知道您是否需要任何帮助。
For reference you can see this plunker: 作为参考,您可以看到这个矮人:
http://plnkr.co/edit/28gANOyhz5mLb7zkhu9W?p=preview
http://plnkr.co/edit/28gANOyhz5mLb7zkhu9W?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.