网页显示使用Angular1.4的表达式中的大括号
Webpage is displaying curly braces from expressions using Angular1.4
由于我是Angular的新手,我希望遇到一些问题,但这个问题似乎时断时续。
当我在这里学习Angular的教程时,我正在学习如何使用表达式。
我试图做的是访问gem
的属性并将其显示在网页上。然而,对象值没有被访问,它只是这样显示:
{{store.product.name}}
${{store.product.price}}
{{store.product.description}}
添加到购物车
我希望它显示为:
Dodechaderon
2.95美元/年
添加到购物车
我想这可能是因为视频使用了Angular1.2,而我使用的是1.4,但我不确定。我做错了什么?如何正确显示对象属性?
这是代码:
(function () {
var app = angular.module('store', []);
app.controller('StoreController', function(){
this.product = gem;
});
var gem = {
name: 'Dodecahaderon',
price: 2.95,
description: '. . . ',
canPurchase = true,
soldOut = true
};
})();
<!DOCTYPE html>
<html ng-app="store">
<head>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
</head>
<body ng-controller="StoreController as store">
<div ng-hide="store.product.soldOut">
<h1>{{store.product.name}}</h1>
<h2>${{store.product.price}}</h2>
<p>{{store.product.description}}</p>
<button ng-show="store.product.canPurchase">Add to Cart</button>
</div>
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>
</body>
</html>
角度库没有被正确引用。打开控制台窗口,确保角度脚本引用确实有效。
当前gem
在控制器范围之外定义。此外,作为gem对象,您必须将=
更改为:
你需要将你的代码更改为这个,它可以
(function () {
var app = angular.module('store', []);
app.controller('StoreController', function(){
this.item = {
name: 'Dodecahaderon',
price: 2.95,
description: '. . . ',
canPurchase : true,
soldOut : true
};
});
})();
和你的html到这个:
<!DOCTYPE html>
<html ng-app="store">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
</head>
<body ng-controller="StoreController as store">
<div ng-hide="store.product.soldOut">
<h1>{{store.item.name}}</h1>
<h2>${{store.item.price}}</h2>
<p>{{store.item.description}}</p>
<button ng-show="store.item.canPurchase">Add to Cart</button>
</div>
</body>
</html>
此外,您可能需要将角度参考从<script type="text/javascript" src="angular.min.js"></script>
替换为<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
相关文章:
- 为什么浏览器为电子邮件验证正则表达式显示不同的反斜杠.如何防止这种情况发生
- 突出显示与perl正则表达式匹配的HTML部分 - 在服务器端perl或客户端javascript中执行此操作
- Angularjs表达式未显示在ngDialog模板中
- AngularJS ng显示表达式在加载时不起作用
- 角度表达式未显示值
- 通过将字符串与 Javascript 中的正则表达式匹配,将字符串替换为突出显示的字符串
- 语法错误,无法识别的表达式,未显示 a[href 和画布
- 正则表达式包装的字符串不显示值
- 正则表达式,用于突出显示文本中的单词
- 如何在 CKeditor 中突出显示与正则表达式匹配的元素
- 网页显示使用Angular1.4的表达式中的大括号
- javascript正则表达式显示“;没有什么可重复的”;
- ng显示表达式..如何调试它
- 在文本中突出显示单词的正则表达式
- 语法高亮显示正则表达式不工作,因为现有的正则表达式匹配
- 如何:修改jquery.自动补全正则表达式以显示从给定输入开始的结果
- 我可以显示普通字符而不是正则表达式吗?
- 无法获得Angularjs在html页面中显示为表达式的结果
- AngularJS:以粗体显示表达式的一部分
- 使用正则表达式显示日期格式