Search code examples
javascriptangularjsiframeplunker

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>

enter image description here

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


Solution

  • There is an error in code:

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

    Right:

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