diff --git a/app/index-async.html b/app/index-async.html index ae63286a5f..3513c3df6a 100644 --- a/app/index-async.html +++ b/app/index-async.html @@ -32,6 +32,7 @@ 'bower_components/angular-route/angular-route.js', 'js/app.js', 'js/services.js', + 'js/providers.js', 'js/controllers.js', 'js/filters.js', 'js/directives.js' diff --git a/app/index.html b/app/index.html index ae7e943cd9..ccad88c12c 100644 --- a/app/index.html +++ b/app/index.html @@ -35,6 +35,7 @@ + diff --git a/app/js/app.js b/app/js/app.js index d990ec7c9d..45617f9205 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -6,11 +6,13 @@ angular.module('myApp', [ 'ngRoute', 'myApp.filters', 'myApp.services', + 'myApp.providers', 'myApp.directives', 'myApp.controllers' ]). -config(['$routeProvider', function($routeProvider) { +config(['$routeProvider', 'InformationProvider', function($routeProvider, InformationProvider) { $routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: 'MyCtrl1'}); $routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: 'MyCtrl2'}); $routeProvider.otherwise({redirectTo: '/view1'}); + InformationProvider.setupInformation('Some info to initialize the information class'); }]); diff --git a/app/js/controllers.js b/app/js/controllers.js index 6ec39e1235..76fc708d5b 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -3,8 +3,8 @@ /* Controllers */ angular.module('myApp.controllers', []) - .controller('MyCtrl1', ['$scope', function($scope) { - + .controller('MyCtrl1', ['$scope', 'Information', function($scope, Information) { + console.log(Information.about()); }]) .controller('MyCtrl2', ['$scope', function($scope) { diff --git a/app/js/providers.js b/app/js/providers.js new file mode 100644 index 0000000000..bd7915da68 --- /dev/null +++ b/app/js/providers.js @@ -0,0 +1,25 @@ +'use strict'; + +/* Providers */ + +angular.module('myApp.providers', []) + .provider('Information', function () { + function Information (about) { + this._about = about; + + this.about = function (about) { + if (about) this._about = about; + + return this._about; + }; + }; + + var aboutInformation = ''; + this.setupInformation = function (about) { + aboutInformation = about; + }; + + this.$get = function () { + return new Information(aboutInformation); + }; + }); \ No newline at end of file