AngularJS的新手,并且不知道在这里发生了什么,当我运行时没有任何东西被填充....
使用版本 - 1.6 请看看,可能是非常愚蠢的问题,但没有通过;)
<!DOCTYPE html>
<html data-ng-app="">
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div data-ng-controller="simpleController">
Name:
<br/>
<input type="text" data-ng-model="fname" />
<br/>
<ul>
<li data-ng-repeat="cust in customers | filter:name | orderBy:'city'">{{ cust.name | uppercase }} - {{ cust.city | lowercase}}</li>
</ul>
</div>
<script src="js/angular.min.js"></script>
<script>
function simpleController($scope){
$scope.customers = [
{name:'anil', city:'bengaluru'},
{name:'rahul', city:'pune'},
{name:'abc', city:'hyd'},
{name:'xyz', city:'mysore'}
];
}
答案 0 :(得分:0)
从angular
创建控制器,然后使用它
代码是:
<!DOCTYPE html>
<html data-ng-app="app">
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div data-ng-controller="simpleController">
Name:
<br/>
<input type="text" data-ng-model="fname" />
<br/>
<ul>
<li data-ng-repeat="cust in customers | filter:name | orderBy:'city'">{{ cust.name | uppercase }} - {{ cust.city | lowercase}}</li>
</ul>
</div>
<script src="js/angular.min.js"></script>
<script>
angular.module("app").controller('simpleController', simpleController);
function simpleController($scope) {
$scope.customers = [{
name: 'anil',
city: 'bengaluru'
}, {
name: 'rahul',
city: 'pune'
}, {
name: 'abc',
city: 'hyd'
}, {
name: 'xyz',
city: 'mysore'
}];
}
</script>
</body>
</html>
答案 1 :(得分:0)
您必须在使用之前创建控制器。 通过以下方式创建控制器:
const c = {x: 'yolo', y: 'rolo', z: 'cholo'};
根据你的代码:
angular.Module("ModuleName",[]).Controller("ControllerName",function($scope){
});
&#13;
答案 2 :(得分:0)
首先,您需要定义一个模块来启动项目。Try this blog to learn more。有关更简单的示例,请尝试this。
要使您的应用有效,您需要将ng-app
封装在您的情况下。然后你需要在你的情况下创建一个module
它缺少。然后根据您的需要添加services
和controller
。
angular.module("app",[])
.controller("ctrl",simpleController);
function simpleController($scope){
$scope.customers = [
{name:'anil', city:'bengaluru'},
{name:'rahul', city:'pune'},
{name:'abc', city:'hyd'},
{name:'xyz', city:'mysore'}
];
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div data-ng-app="app" data-ng-controller="simpleController">
Name:
<br/>
<input type="text" data-ng-model="fname" />
<br/>
<ul>
<li data-ng-repeat="cust in customers | filter:name | orderBy:'city'">{{ cust.name | uppercase }} - {{ cust.city | lowercase}}</li>
</ul>
</div>