繁体   English   中英

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]);

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';
});

你拼错controller作为contoller

这是一个简单的示例,让您开始使用“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';
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM