1

From Documentation

The syntax InvoiceController as invoice tells Angular to instantiate the controller and save it in the variable invoice in the current scope.

We also changed all expressions in the page to read and write variables within that controller instance by prefixing them with invoice.

<!DOCTYPE html>
<html>

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link href="style.css" rel="stylesheet" />
    <script data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular.js" data-require="angular.js@1.3.x"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="InvoiceController as invoice">
    <p>Hello {{invoice.name}}!</p>
  </body>

</html>

JS

var app = angular.module('plunker', []);

app.controller('InvoiceController', function() {
  this.name = 'World';
});

But it is not working as mentioned in the document. I just moved the inline scripts to external file.

PLUNKER DEMO

Also why it is not working if i pass $scope to the controller function

app.controller('InvoiceController', function($scope) {
  $scope.name = 'World';
});
Billa
  • 5,226
  • 23
  • 61
  • 105
  • http://stackoverflow.com/questions/11605917/this-vs-scope-in-angularjs-controllers?rq=1 – Billa Mar 19 '15 at 12:03

1 Answers1

3

You forgot to set the ng-app

<html ng-app="plunker">
<!-- REST OF HTML -->
</html>
Huy Hoang Pham
  • 4,107
  • 1
  • 16
  • 28