Thanks Sander, I will check out the styleguide.
I'm already using grunt so i'll check out ngannotate - i thought it was just for safe minifying i'm not sure it will save me that much time. In regards to writing the controllerAs way, as you can see in my code the angular.extend is inside the SettingsController, but the examples have it outside and it would be angular.extend(SetttingsCtrl.prototype, ... I couldn't get that method to work due to a race condition, the .extend call on the prototype runs before the function SettingsCtrl is run so nothing is defined - am i missing something here? thanks Greg On Wednesday, December 10, 2014 12:00:55 AM UTC-8, Sander Elias wrote: > > Hi Greg, > > First of all, read trough the recommend style-guide > <https://github.com/johnpapa/angularjs-styleguide>. It will make quite a > few things more clear, and it will also explain the why's. You don't have > to follow the guide verbatim, but it will get you on the right track. > >> 1. what is the right/better approach >> > controllerAs is the "right" approach > > >> 2. Is there another way to inject using controllerAs >> > Yes, but stop doing it by hand, use ng-annotate, there are vesrions for > both grunt and gulp. (You need a build tool anyway for a larger build!) > > >> 3. Is there a performance difference and a good way to test this? >> > No, however, in building a larger system, the controllerAs would probably > be faster, as its inheritance chain is way shorter then the $scope chain. > > >> >> angular.module('sdt.settingsctrl', []) >> .controller('SettingsCtrl', SettingsCtrl); >> >> SettingsCtrl.$inject= ['$log', 'ModalService', 'SettingsModel']; >> >> function SettingsCtrl($log, ModalService, SettingsModel){ >> angular.extend(this, { >> data: SettingsModel.getData(), >> settings: SettingsModel.settings(), >> open: function() { >> var items = [{item: 'item1'}, {item: 'item2'}, {item: 'item3'}]; >> var modalOptions = { >> closeButtonText: 'Cancel', >> actionButtonText: 'OK', >> headerText: 'Adjust your settings', >> bodyText: items, >> result: this.callBack(), >> >> //optional - if you use this option feel free to >> //add more properties to work with your custom template >> template: 'partials/modals/settings.html' >> } >> >> >> ModalService.showModal({}, modalOptions).then(function (result) { >> $log.log(result); >> }) >> }, >> callBack: function() { >> return SettingsModel.settings(); >> } >> }) >> >> }; >> >> >> > You really should look over the styleguide, you are making it way more > complex then needed! > > Regards > Sander > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
