Angularjs 正在运行的示例
我正在学习angularJS,并且很难从培训视频中获得以下示例代码。有人能告诉我哪里出了问题吗 当我从第二个版本更改它时,它停止工作,如下所示。第二个版本运行良好,但当我尝试模块化控制器时,它崩溃了Angularjs 正在运行的示例,angularjs,Angularjs,我正在学习angularJS,并且很难从培训视频中获得以下示例代码。有人能告诉我哪里出了问题吗 当我从第二个版本更改它时,它停止工作,如下所示。第二个版本运行良好,但当我尝试模块化控制器时,它崩溃了 <html ng-app="demoApp"> <head> <title>Hello World, AngularJS</title> </head> <body> &l
<html ng-app="demoApp">
<head>
<title>Hello World, AngularJS</title>
</head>
<body>
<div ng-controller="SimpleController">
<br/>
<input type="text" ng-model="name"/>
<br/>
<ul>
<li ng-repeat="cust in customers | filter:name | orderBy:salary">
{{ cust.name | uppercase}} -
{{ cust.city | lowercase }} -
{{ cust.salary | currency }}
</li>
</ul>
</div>
<script>
var demoApp = angular.module('demoApp',[]);
demoApp.controller('SimpleController', ['', function($scope){
$scope.customers = [
{name: 'John Smith', city: 'Phoenix', salary: 90000, hired: '2014-04-04'},
{name: 'Jenny Linn', city: 'New York', salary: 94000, hired: '2014-04-04'},
{name: 'Johnson Holmes', city: 'Los Angeles', salary: 96000, hired: '2014-04-04'},
{name: 'Thomas Muffin', city: 'Chicago', salary: 80000, hired: '2014-04-17'}
]}])
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
</body>
</html>
你好,世界,安格拉斯
-
{{cust.name |大写}}-
{{cust.city}小写}-
{{客户工资|货币}
var demoApp=angular.module('demoApp',[]);
demoApp.controller('SimpleControl',['',函数($scope){
$scope.customers=[
{姓名:'John Smith',城市:'Phoenix',工资:90000,雇佣:'2014-04-04'},
{姓名:'Jenny Linn',城市:'New York',工资:94000,雇佣:'2014-04-04'},
{姓名:'Johnson Holmes',城市:'Los Angeles',工资:96000,雇佣:'2014-04-04'},
{姓名:'Thomas Muffin',城市:'Chicago',工资:80000,雇佣:'2014-04-17'}
]}])
有效版本:
<html ng-app="">
<head>
<title></title>
</head>
<body>
<div ng-controller="SimpleController">
<input type="text" ng-model="nameInput" /> <span style="font-weight:bold"> {{ nameInput }}</span>
<h3>Listing1</h3>
<ul>
<li ng-repeat="cust in customers | filter: nameInput | orderBy: 'city' ">
{{ cust.name | uppercase }} - {{ cust.city }} - {{ cust.salary }} - {{ cust.hired | date:'yyyy-MM-dd' }}
</li>
</ul>
</div>
<script>
function SimpleController($scope) {
$scope.customers = [
{name: 'John Smith', city: 'Phoenix', salary: 90000, hired: '2014-04-04'},
{name: 'Jenny Linn', city: 'New York', salary: 94000, hired: '2014-04-04'},
{name: 'Johnson Holmes', city: 'Los Angeles', salary: 96000, hired: '2014-04-04'},
{name: 'Thomas Muffin', city: 'Chicago', salary: 80000, hired: '2014-04-17'}
]; }
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
</body>
</html>
{{nameInput}}
清单1
-
{{cust.name |大写}-{{cust.city}-{{cust.salary}-{{cust.hired |日期:'yyyy-MM-dd'}
函数SimpleController($scope){
$scope.customers=[
{姓名:'John Smith',城市:'Phoenix',工资:90000,雇佣:'2014-04-04'},
{姓名:'Jenny Linn',城市:'New York',工资:94000,雇佣:'2014-04-04'},
{姓名:'Johnson Holmes',城市:'Los Angeles',工资:96000,雇佣:'2014-04-04'},
{姓名:'Thomas Muffin',城市:'Chicago',工资:80000,雇佣:'2014-04-17'}
]; }
在模块化示例中,您需要将$scope传递到控制器中
demoApp.controller('SimpleController', ['$scope', function($scope){
$scope.customers = [
{name: 'John Smith', city: 'Phoenix', salary: 90000, hired: '2014-04-04'},
{name: 'Jenny Linn', city: 'New York', salary: 94000, hired: '2014-04-04'},
{name: 'Johnson Holmes', city: 'Los Angeles', salary: 96000, hired: '2014-04-04'},
{name: 'Thomas Muffin', city: 'Chicago', salary: 80000, hired: '2014-04-17'}
]}])
在模块化示例中,需要将$scope传递到控制器中
demoApp.controller('SimpleController', ['$scope', function($scope){
$scope.customers = [
{name: 'John Smith', city: 'Phoenix', salary: 90000, hired: '2014-04-04'},
{name: 'Jenny Linn', city: 'New York', salary: 94000, hired: '2014-04-04'},
{name: 'Johnson Holmes', city: 'Los Angeles', salary: 96000, hired: '2014-04-04'},
{name: 'Thomas Muffin', city: 'Chicago', salary: 80000, hired: '2014-04-17'}
]}])
在模块化示例中,需要将$scope传递到控制器中
demoApp.controller('SimpleController', ['$scope', function($scope){
$scope.customers = [
{name: 'John Smith', city: 'Phoenix', salary: 90000, hired: '2014-04-04'},
{name: 'Jenny Linn', city: 'New York', salary: 94000, hired: '2014-04-04'},
{name: 'Johnson Holmes', city: 'Los Angeles', salary: 96000, hired: '2014-04-04'},
{name: 'Thomas Muffin', city: 'Chicago', salary: 80000, hired: '2014-04-17'}
]}])
在模块化示例中,需要将$scope传递到控制器中
demoApp.controller('SimpleController', ['$scope', function($scope){
$scope.customers = [
{name: 'John Smith', city: 'Phoenix', salary: 90000, hired: '2014-04-04'},
{name: 'Jenny Linn', city: 'New York', salary: 94000, hired: '2014-04-04'},
{name: 'Johnson Holmes', city: 'Los Angeles', salary: 96000, hired: '2014-04-04'},
{name: 'Thomas Muffin', city: 'Chicago', salary: 80000, hired: '2014-04-17'}
]}])
这里有两个问题
“$scope”
注入控制器
放在所有其他javascript标记之前
<html ng-app="demoApp">
<head>
<title>Hello World, AngularJS</title>
</head>
<body>
<div ng-controller="SimpleController">
<br/>
<input type="text" ng-model="name"/>
<br/>
<ul>
<li ng-repeat="cust in customers | filter:name | orderBy:salary">
{{ cust.name | uppercase}} -
{{ cust.city | lowercase }} -
{{ cust.salary | currency }}
</li>
</ul>
</div>
<!-- load your angular core script files first -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<script>
var demoApp = angular.module('demoApp',[]);
demoApp.controller('SimpleController', ['$scope', function($scope){
$scope.customers = [
{name: 'John Smith', city: 'Phoenix', salary: 90000, hired: '2014-04-04'},
{name: 'Jenny Linn', city: 'New York', salary: 94000, hired: '2014-04-04'},
{name: 'Johnson Holmes', city: 'Los Angeles', salary: 96000, hired: '2014-04-04'},
{name: 'Thomas Muffin', city: 'Chicago', salary: 80000, hired: '2014-04-17'}
]}])
</script>
</body>
</html>
你好,世界,安格拉斯
-
{{cust.name |大写}}-
{{cust.city}小写}-
{{客户工资|货币}
var demoApp=angular.module('demoApp',[]);
demoApp.controller('SimpleControl',['$scope',函数($scope){
$scope.customers=[
{姓名:'John Smith',城市:'Phoenix',工资:90000,雇佣:'2014-04-04'},
{姓名:'Jenny Linn',城市:'New York',工资:94000,雇佣:'2014-04-04'},
{姓名:'Johnson Holmes',城市:'Los Angeles',工资:96000,雇佣:'2014-04-04'},
{姓名:'Thomas Muffin',城市:'Chicago',工资:80000,雇佣:'2014-04-17'}
]}])
“$scope”
注入控制器
放在所有其他javascript标记之前
<html ng-app="demoApp">
<head>
<title>Hello World, AngularJS</title>
</head>
<body>
<div ng-controller="SimpleController">
<br/>
<input type="text" ng-model="name"/>
<br/>
<ul>
<li ng-repeat="cust in customers | filter:name | orderBy:salary">
{{ cust.name | uppercase}} -
{{ cust.city | lowercase }} -
{{ cust.salary | currency }}
</li>
</ul>
</div>
<!-- load your angular core script files first -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<script>
var demoApp = angular.module('demoApp',[]);
demoApp.controller('SimpleController', ['$scope', function($scope){
$scope.customers = [
{name: 'John Smith', city: 'Phoenix', salary: 90000, hired: '2014-04-04'},
{name: 'Jenny Linn', city: 'New York', salary: 94000, hired: '2014-04-04'},
{name: 'Johnson Holmes', city: 'Los Angeles', salary: 96000, hired: '2014-04-04'},
{name: 'Thomas Muffin', city: 'Chicago', salary: 80000, hired: '2014-04-17'}
]}])
</script>
</body>
</html>
你好,世界,安格拉斯
-
{{cust.name |大写}}-
{{cust.city}小写}-
{{客户工资|货币}
var demoApp=angular.module('demoApp',[]);
demoApp.controller('SimpleControl',['$scope',函数($scope){
$scope.customers=[
{姓名:'John Smith',城市:'Phoenix',工资:90000,雇佣:'2014-04-04'},
{姓名:'Jenny Linn',城市:'New York',工资:94000,雇佣:'2014-04-04'},
{姓名:'Johnson Holmes',城市:'Los Angeles',工资:96000,雇佣:'2014-04-04'},
{姓名:'Thomas Muffin',城市:'Chicago',工资:80000,雇佣:'2014-04-17'}
]}])
“$scope”
注入控制器
放在所有其他javascript标记之前
<html ng-app="demoApp">
<head>
<title>Hello World, AngularJS</title>
</head>
<body>
<div ng-controller="SimpleController">
<br/>
<input type="text" ng-model="name"/>
<br/>
<ul>
<li ng-repeat="cust in customers | filter:name | orderBy:salary">
{{ cust.name | uppercase}} -
{{ cust.city | lowercase }} -
{{ cust.salary | currency }}
</li>
</ul>
</div>
<!-- load your angular core script files first -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<script>
var demoApp = angular.module('demoApp',[]);
demoApp.controller('SimpleController', ['$scope', function($scope){
$scope.customers = [
{name: 'John Smith', city: 'Phoenix', salary: 90000, hired: '2014-04-04'},
{name: 'Jenny Linn', city: 'New York', salary: 94000, hired: '2014-04-04'},
{name: 'Johnson Holmes', city: 'Los Angeles', salary: 96000, hired: '2014-04-04'},
{name: 'Thomas Muffin', city: 'Chicago', salary: 80000, hired: '2014-04-17'}
]}])
</script>
</body>
</html>
你好,世界,安格拉斯
-
{{cust.name |大写}}-
{{cust.city}小写}-
{{客户工资|货币}
var demoApp=angular.module('demoApp',[]);
demoApp.controller('SimpleControl',['$scope',函数($scope){
$scope.customers=[
{姓名:'John Smith',城市:'Phoenix',工资:90000,雇佣:'2014-04-04'},
{姓名:'Jenny Linn',城市:'New York',工资:94000,雇佣:'2014-04-04'},
{姓名:'Johnson Holmes',城市:'Los Angeles',工资:96000,雇佣:'2014-04-04'},
{姓名:'Thomas Muffin',城市:'Chicago',工资:80000,雇佣:'2014-04-17'}
]}])