简体   繁体   中英

Why does “hello world” angularJS code throws A LOT OF errors on Plunker?

The demo can be viewed at:

http://plnkr.co/edit/tLiAWIQ3bCAo4z4VFYTc?p=preview

script.js

var app=angular.module('app',[])
app.controller('MyController', function($scope) {
  console.log("TEST")
  $scope.on("$destroy", function() {console.log("DESTROY")})
})

index.html:

<!DOCTYPE html>
<html ng-app='app'>

  <head>
    <script data-require="angular.js@*" data-semver="1.4.0-beta.3" src="https://code.angularjs.org/1.4.0-beta.3/angular.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body ng-controller="MyController">
    <h1>Hello Plunker!</h1>
  </body>

</html>

在此处输入图片说明

Does anyone have ideas about why so many errors are throwed in plunkr? Is there a way to deal with this?

There is an error in code:

$scope.on("$destroy", function() {console.log("DESTROY")})

Right:

$scope.$on("$destroy", function() {console.log("DESTROY")})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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