gpt4 book ai didi

angularjs - Angular ng-controller 问题

转载 作者:行者123 更新时间:2023-12-03 08:16:35 26 4
gpt4 key购买 nike

正在接受 AngularJS 的基本培训,但是一开始就卡住了,因为表达式没有使用 ng-controller 依赖项进行评估。

index.html

<html ng-app="store">
<head>
<title>Angular JS</title>
<link rel="Stylesheet" type="text/css" href="bootstrap.min.css" />
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body>
<h1>{{"Hello"}}</h1>
<div ng-controller="StoreController as stores">

<h1> {{stores.products.name}} </h1>
<h2> {{stores.products.price}} </h2>
<p> {{stores.products.description}} </p>
</div>
</body>
</html>

app.js

(function () {

var app = angular.module("store", []);
app.controller = ('StoreController', function () {
this.products = gem;
});
var gem =
{
name:'New Product',
price:'2.95',
description: 'This is something you would need to buy!!'
}
})();

HTML 输出

Hello
{{stores.products.name}}
{{stores.products.price}}
{{stores.products.description}}

请帮我看看我做错了什么。

最佳答案

您的 Controller 中有一个不正确的 = 符号。

(function () {

var app = angular.module("store", []);
////NOT app.controller = ('StoreController'.....
app.controller('StoreController', function () {
this.products = gem;
});
var gem =
{
name:'New Product',
price:'2.95',
description: 'This is something you would need to buy!!'
}
})();

关于angularjs - Angular ng-controller 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25486339/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com