AngularJS 简单示例在 Plunker 中不起作用
AngularJS easy example doesn't work in Plunker
我不明白为什么这个简单的例子在 Plunker 中不起作用。
http://plnkr.co/edit/EfNxzzQhAb8xAcFZGKm3?p=preview
var app = angular.module("App",[]);
var Controller = function($scope){
$scope.message ="Hello";
};
app.contoller("Controller",['$scope',Controller]);
var app = angular.module("App",[]);
var Controller = function($scope){
$scope.message ="Hello";
};
app.contoller("Controller",['$scope',Controller]);
您将 controller
拼错为 contoller
。
Plunker 提供开箱即用的 angular 语法,让您开始最佳实践:
看看这个:
http://plnkr.co/edit/tpl:8rFfZljYNl3z1A4LKSL2?p=preview
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.0-rc.2/angular.js" data-semver="1.4.0-rc.2"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
</body>
</html>
JS:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
这是一个让您开始使用 "Controller as" 语法的简单示例,这是您今后应该使用的语法。您会看到很多 $scope 语法的示例,但它不再是将控制器绑定到视图的推荐方式。有关详细信息,请参阅 AngularJS.org's documentation regarding ngController。
笨蛋:http://plnkr.co/edit/aydvXaJNXtzdVI1mh2I4?p=preview
HTML:
<!DOCTYPE html>
<html ng-app="controllerAsDemo">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.0-rc.2/angular.js" data-semver="1.4.0-rc.2"></script>
<script src="app.js"></script>
</head>
<body >
<p ng-controller="MainController as main">Hello {{main.name}}!</p>
<p ng-controller="BillyGoatController as billyGoat">Hello {{billyGoat.name}}!</p>
</body>
</html>
JS:
var app = angular.module('controllerAsDemo', []);
app.controller('MainController', function() {
this.name = 'World';
});
app.controller('BillyGoatController', function() {
this.name = 'Billy Goat Gruff';
})
我不明白为什么这个简单的例子在 Plunker 中不起作用。
http://plnkr.co/edit/EfNxzzQhAb8xAcFZGKm3?p=preview
var app = angular.module("App",[]);
var Controller = function($scope){
$scope.message ="Hello";
};
app.contoller("Controller",['$scope',Controller]);
var app = angular.module("App",[]);
var Controller = function($scope){
$scope.message ="Hello";
};
app.contoller("Controller",['$scope',Controller]);
您将 controller
拼错为 contoller
。
Plunker 提供开箱即用的 angular 语法,让您开始最佳实践:
看看这个:
http://plnkr.co/edit/tpl:8rFfZljYNl3z1A4LKSL2?p=preview
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.0-rc.2/angular.js" data-semver="1.4.0-rc.2"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
</body>
</html>
JS:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
这是一个让您开始使用 "Controller as" 语法的简单示例,这是您今后应该使用的语法。您会看到很多 $scope 语法的示例,但它不再是将控制器绑定到视图的推荐方式。有关详细信息,请参阅 AngularJS.org's documentation regarding ngController。
笨蛋:http://plnkr.co/edit/aydvXaJNXtzdVI1mh2I4?p=preview
HTML:
<!DOCTYPE html>
<html ng-app="controllerAsDemo">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.0-rc.2/angular.js" data-semver="1.4.0-rc.2"></script>
<script src="app.js"></script>
</head>
<body >
<p ng-controller="MainController as main">Hello {{main.name}}!</p>
<p ng-controller="BillyGoatController as billyGoat">Hello {{billyGoat.name}}!</p>
</body>
</html>
JS:
var app = angular.module('controllerAsDemo', []);
app.controller('MainController', function() {
this.name = 'World';
});
app.controller('BillyGoatController', function() {
this.name = 'Billy Goat Gruff';
})