Javascript – Angular JS not working in plunker


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>

    <script data-require="angular.js@*" data-semver="1.3.15" src=""></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>

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


Contents of javascript script.js file

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


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.