我的角度代码有什么问题? [英] WHat is wrong with my angular code ?
本文介绍了我的角度代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< !doctype html >
< html data-ng -app = store >
< head >
< title > 角度演示< / title >
< link rel = stylesheet type = text / css href = bootstrap.min.css >
< script type = text / javascript src = jquery-1.8.2.js > < / script >
< script src = bootstrap.min.js > < / script >
< script src = http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular.js < span class =code-keyword>> < / script >
< / head >
< 正文 >
< ; div data-ng-controller = itemController as store >
< ul class = list-group >
< li class = list-group-item data-ng-repeat = store.product.names中的产品 >
< h3 > {{store.product.name}}
< em class = pull-right > {{store.product.price}} < / em >
< / h3 >
< / li >
< < span class =code-leadattribute> / ul >
< ; / div >
< script type = text / javascript >
(function(){
var app = angular.module('store',[]);
app.controller('itemController',函数($ scope){
$ scope.product = gem;
});
var gem = [
{name:'Item1',price:15},
{name:'Item2',price:16},
{name :'Item3',价格:17},
{名称:'Item4',价格:18},
{名称:'Item5',价格:19}];
})();
< / script >
<! - < span class =code-keyword> < script src =jquery.js>< / script> - >
< script src = app.js > < / script >
< / body >
< / HTML 跨度> <温泉n class =code-keyword>>
在浏览器上查看页面并检查控制台页面后,我收到此错误消息
错误:[ng:areq]参数'itemController'不是函数,未定义
解决方案
scope){
scope.product = gem;
});
var gem = [
{name:'Item1',price:15},
{name:'Item2',price:16},
{name :'Item3',价格:17},
{名称:'Item4',价格:18},
{名称:'Item5',价格:19}];
})();
< / script >
<! - < span class =code-keyword> < script src =jquery.js>< / script> - >
< script src = app.js > < / script >
< / body >
< / HTML 跨度> <温泉n class =code-keyword>>
在浏览器上查看页面并检查控制台页面后,我收到此错误消息
错误:[ng:areq]参数'itemController'不是函数,未定义
你不应该使用带有ng-Repeat的product.names。
此外,打印值删除存储。
尝试以下代码:
< html data-ng- app = store >
< head >
< title > 角度演示< / title >
< < span class =code-leadattribute> link rel = 样式表 类型 = text / css href = bootstrap.min.css >
< script type = text / javascript src = jquery-1.8.2.js > < / script >
< script src = bootstrap.min.js > < / script >
< script src = http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular.js > < / script >
< / head >
< 正文 >
< div data-ng- controller = itemController as store >
< ul class = 列表组 >
< li class = list-group-item data-ng-repeat = 产品中的产品 >
< h3 > {{product.name}}
{{product .price}}
< / h3 >
< / li >
< / ul >
< / div >
< 脚本 类型 = text / javascript >
( function (){
var app = angular.module(' store',[]);
app.controller(' itemController',功能跨度>(
<!doctype html>
<html data-ng-app="store" >
<head>
<title>Angular Demo</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<script type="text/javascript" src="jquery-1.8.2.js"></script>
<script src="bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular.js"></script>
</head>
<body >
<div data-ng-controller="itemController as store">
<ul class="list-group">
<li class="list-group-item" data-ng-repeat="product in store.product.names">
<h3>{{store.product.name}}
<em class="pull-right">{{store.product.price}}</em>
</h3>
</li>
</ul>
</div>
<script type="text/javascript">
(function(){
var app = angular.module('store',[]);
app.controller('itemController',function($scope){
$scope.product = gem;
});
var gem = [
{name:'Item1', price:15},
{name:'Item2', price:16},
{name:'Item3', price:17},
{name:'Item4', price:18},
{name:'Item5', price:19}];
})();
</script>
<!-- <script src="jquery.js"></script>-->
<script src="app.js"></script>
</body>
</html>
After viewing the page on my browser and checked the console page, i received this error message
Error: [ng:areq] Argument 'itemController' is not a function, got undefined
解决方案
scope){
scope.product = gem; }); var gem = [ {name:'Item1', price:15}, {name:'Item2', price:16}, {name:'Item3', price:17}, {name:'Item4', price:18}, {name:'Item5', price:19}]; })(); </script> <!-- <script src="jquery.js"></script>--> <script src="app.js"></script> </body> </html>
After viewing the page on my browser and checked the console page, i received this error message
Error: [ng:areq] Argument 'itemController' is not a function, got undefined
You should not use product.names with ng-Repeat.
Also, While printing values remove "store."
Try Below Code :
<html data-ng-app="store" > <head> <title>Angular Demo</title> <link rel="stylesheet" type="text/css" href="bootstrap.min.css"> <script type="text/javascript" src="jquery-1.8.2.js"></script> <script src="bootstrap.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular.js"></script> </head> <body > <div data-ng-controller="itemController as store"> <ul class="list-group"> <li class="list-group-item" data-ng-repeat="product in product"> <h3>{{product.name}} {{product.price}} </h3> </li> </ul> </div> <script type="text/javascript"> (function(){ var app = angular.module('store',[]); app.controller('itemController',function(
这篇关于我的角度代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文