Javascript – Angular JS not working in plunker

angularjsjavascript

I couldn't get my angular code to run in plunker. I have attached the details. Could any of you help me out? Basically it's a problem with ngcontroller I guess but I am not sure.

<!DOCTYPE html>
<html ng-app>

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

  <body ng-controller="MainController">
    {{ 5 / 2 }}<br>
    {{message}}
  </body>

</html>

Contents of javascript script.js file

var MainController = function($scope){
  $scope.message = "Welcome!";
};

Plunk
http://plnkr.co/edit/mzgdELALCP7DN2ikJHsC?p=preview

Best Solution

In version 1.3.*, you cannot longer declare a global controller function.

Instead define a module, and use your controller function:

var SidController = function($scope){

  $scope.message = "WElcome.";

};
SidController.$inject = ['$scope'];
angular.module('app', []).controller('SidController', SidController);

In your html

<html ng-app="app">

See this plunker.