OK I checked the styleguide and i see what you mean by over complicating it.
New code.
function SettingsController($log, ModalService, SettingsModel, $translate,
$filter){
var sc_vm = this;
sc_vm.data = SettingsModel.getData();
sc_vm.settings = SettingsModel.settings();
sc_vm.applySettings = false;
sc_vm.open = function() {
var items = [{item: 'item1'}, {item: 'item2'}, {item: 'item3'}];
var modalOptions = {
closeButtonText: 'Cancel',
actionButtonText: 'OK',
headerText: $filter('translate')('SETTINGS_MODAL_HEADER_TEXT'),
bodyText: items,
//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('apply settings ', sc_vm, sc_vm.applySettings);
// TODO: Implement proper settings model which can be restored on
Cancel
if(result.id == 'cancel') {
// TODO: reset any changed values to original state
result.applySettings = false;
}
// Fired only on OK && settings have changed
if(result.id == 'ok' && result.custom.apply) {
$log.log('hello', SettingsModel.settings().language.code)
$translate.use(SettingsModel.settings().language.code);
}
// $log.log(result);
});
};
sc_vm.updateSettings = function() {
sc_vm.applySettings = true;
$log.log(sc_vm);
ModalService.setCustomOptions({apply: sc_vm.applySettings});
}
};
i think this is better - correct?
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.