控制器在角不能被1.3后初始化全局 [英] Controller in angular can't be initialized globally after 1.3
本文介绍了控制器在角不能被1.3后初始化全局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想学习AngularJs控制器和范围,但我总是得到这个错误:[NG:AREQ]参数'studentController不是一个函数,得到了不确定
当我运行这个code。
< HTML和GT;
< HEAD>
<标题> AngularJs< /标题>
<脚本SRC =脚本/ angular.js>< / SCRIPT>
< /头>
<身体GT;
< DIV NG-应用=NG控制器=studentController>
< DIV CLASS =容器>
<输入类型=文本NG模型=名>
< BR>
< H2>使用NG-init和NG-重复&LT列表名称; / H>
< UL>
<李NG重复=卡斯特在客户|过滤器:名称|排序依据:城市>
{{cust.name}} - {{cust.city}}
< /李>
< / UL>
< / DIV>
< / DIV>
<脚本>
功能studentController($范围){
$ scope.customers = [
{名称:'约翰·斯密特,城市:伊夫兰},
{名称:'Nurcan土耳其,城市:伊兹密尔},
{名称:'劳拉·凯勒,城市:科隆},
{名称:'萨姆Haimoura,城市:Harhoura},
{名称:'Brayan在一片,城市:卡萨布兰卡}
];
};
< / SCRIPT>< /身体GT;
尽管这code是莫名其妙地直接从一个教程。有人可以告诉我有什么不对的code
解决方案
< DIV NG-应用=APPNAMENG控制器=StudentController>
VAR应用= angular.module('APPNAME',[]);
app.controller('StudentController','');
I am trying to learn Controllers and Scopes in AngularJs, but I always get this Error: [ng:areq] Argument 'studentController' is not a function, got undefined
, when I run this code.
<html >
<head>
<title>AngularJs</title>
<script src="script/angular.js"></script>
</head>
<body>
<div ng-app="" ng-controller="studentController">
<div class="container" >
<input type="text" ng-model="name">
<br>
<h2>List name using ng-init and ng-repeat</h2>
<ul>
<li ng-repeat="cust in customers | filter : name | orderBy:'city' ">
{{ cust.name }} - {{ cust.city }}
</li>
</ul>
</div>
</div>
<script>
function studentController($scope) {
$scope.customers = [
{name : 'John Smit', city : 'Ifrane'},
{name : 'Nurcan Turkey', city : 'Izmir'},
{name : 'Laura Keller', city : 'Cologne'},
{name : 'Sam Haimoura', city : 'Harhoura'},
{name : 'Brayan Amid', city : 'Casablanca'}
];
};
</script>
</body>
Even though this code is somehow directly from a tutorial. Can someone please tell me what's wrong with this code
解决方案
<div ng-app="appname" ng-controller="StudentController">
var app = angular.module('appname', []);
app.controller('StudentController','');
这篇关于控制器在角不能被1.3后初始化全局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文