Angular: Bootstrap third party module

Bootstrap a third-party module in Angular.

by Matthew Pavkov

HTML

<script src="https://code.angularjs.org/1.4.8/angular.min.js"></script>
<div ng-controller="AppCtrl">
  Hello, {{name}}!
</div>

<div ng-controller="MyWidgetCtrl">
  My widget is called {{widgetName}}
</div>

JavaScript

// Parent/host application
var myApp = angular.module('myApp', []);
myApp
	.config(
    	function() {
			console.log('config section');
		}
    )
    .run([
    	'$animate', 
        function($animate) {
        	console.log('run section');
        	$animate.enabled(false);
    	}
    ])
	.controller('AppCtrl',
    	function($scope) {
        	console.log('controller section');
        	$scope.name = 'Claire';
    	}
	);


// Third party module
// This needs to happen after myApp is defined
var myWidget = angular.module('myApp');
myWidget
	.config(
    	function() {
        	console.log('widget - config section');
        }
	)
	.controller('MyWidgetCtrl', [
    	'$scope',
        function($scope) {
        	console.log('widget - controller section');
            $scope.widgetName = 'Widgetmania';
        }
    ]);