2

我不明白为什么这个简单的例子在 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]);
4

3 回答 3

4

Plunker 提供开箱即用的角度语法,让您开始使用最佳实践:

看一下这个:

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';
});
于 2015-05-25T23:37:39.003 回答
3

你拼错controllercontoller

于 2015-05-25T23:32:59.403 回答
2

这是一个简单的示例,可让您开始使用“Controller as”语法,这是您以后应该使用的语法。您会看到很多$scope语法的示例,但它不再是将控制器绑定到视图的推荐方法。有关更多详细信息,请参阅 AngularJS.org 的有关 ngController 的文档

Plunker: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';
})
于 2015-05-26T00:53:33.890 回答