app/js/controllers.js:
function PhoneListCtrl($scope, $http) {
$http.get('phones/phones.json').success(function(data) {
$scope.phones = data;
});
$scope.orderProp = 'age';
}
angular.module('YourApp').controller('ControllerName', function($scope) {})
I would vote for this to change in the tutorial as it doesn't fit well with the high quality engineered approach that angular promotes
Pete
...from my mobile.
Is this a serious question?
One nice thing about modules is that they are pluggable so even if the file containing the module is loaded you can choose not to use it by not depending upon it. In the same vein you can setup dependencies between modules containing controllers which you can't do between global objects.
Pete
...from my mobile.
// Declare app level module which depends on filters, and servicesangular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives']).
// Declare app level module which depends on filters, directive, controllers and servicesangular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers']).
'use strict';/* Controllers */angular.module('myApp.controllers', []).controller('MyCtrl1',function MyCtrl1() {}).controller('MyCtrl2', function MyCtrl2() {});
MyCtrl1.$inject = [];
MyCtrl2.$inject = [];
--
--
controller('MyCtrl1',function MyCtrl1() {
}).$inject = [];
Jennifer
From your examples, you always have controllers created in the global name space like so:app/js/controllers.js:
function PhoneListCtrl($scope, $http) {
$http.get('phones/phones.json').success(function(data) {
$scope.phones = data;
});
$scope.orderProp = 'age';
}From my limited experience with AngulaJS and JavaScript I believe this is a really bad practise?I saw an article (not-polluting-global-with-angularjs) referencing the controller function of module as a way to avoid itangular.module('YourApp').controller('ControllerName', function($scope) {})So my question is, what is the best practise here? Seems namespace pollution is a bad idea, yet all the examples do it.ThanksDes
Look closely to where you get that exception from. You have removed MyCtrl from the global name space and you are still trying to reference it somewhere as it was still global. Replace that reference with a string 'MyCtrl' and you will be fine. I bet this is in $route configuration.
Regards,
Witold Szczerba
---
Sent from my mobile phone.
--
Have you registered the module of that controller in your test?
Regards,
Witold Szczerba
---
Sent from my mobile phone.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.