Angular controlleras syntax

Description

A-Level Angular Note on Angular controlleras syntax, created by James Drummond on 18/12/2015.
James Drummond
Note by James Drummond, updated more than 1 year ago
James Drummond
Created by James Drummond almost 9 years ago
2
0

Resource summary

Page 1

The syntax InvoiceController as invoice tells Angular to instantiate the controller and save it in the variable invoice in the current scope.What this means is that you can treat the controller as an object:myApp.controller()You need to be very careful about context: this is what you need to do to use $scope.$watch with this syntax: note binding of thisapp.controller('MainCtrl', function ($scope) { this.title = 'Some title'; // boom $scope.$watch(angular.bind(this, function () { return this.title; // `this` IS the `this` above!! }), function (newVal, oldVal) { // now we will pickup changes to newVal and oldVal }); });

Show full summary Hide full summary

Similar

Angular Nuts and Bolts
James Drummond
Angular application scaffolding
James Drummond
Angular-hint
James Drummond
ng-model-options
James Drummond
Architecture and general layout
James Drummond
Quiz - Object Oriented Javascript
arunram.krish
Examen Fundamentos Basicos de Programación
Jose Valderrama0721
Test I. Introduction to web technologies
Angel Martínez Rodriguez
The Princeton Review Chapter 9 Rotational Motion
Anibal Santamaria
Angular
Kingsley Bawuah
JavaScript Fundamentals
Andrew Watters