Angular module.controller() Example

Demonstrates hanging an angular controller off of a module, so as not to pollute the global namespace.

by jeklund

HTML

<div ng-app=MyModule>
    <div ng-controller=myName>
        <h1>{{label}}</h1>
    </div>
</div>

JavaScript

'use strict';

var MyController = function MyController() {
	this.$onInit = function onInit() {
    this.label = 'haha';
    console.log('hey');
  };
};

var MySelector = {
	controller: MyController,
  bindings: {
  	label: '@'
  }
}

MySelector.registeredName = 'myName';

angular.module('MyModule', [])
.component(MySelector.registeredName, MySelector);