Created
October 25, 2014 00:48
-
-
Save srph/13d528e566e0c3b0729c to your computer and use it in GitHub Desktop.
unable to access isolated scope's variables from this with the controllerAs syntax / style.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| +(function(angular, _, undefined) { | |
| function PaginationCtrl($scope) { | |
| // view-model | |
| var vm = this; | |
| vm.decodeQuery = decodeQuery; | |
| vm.getData = getData; | |
| vm.goToPage = goToPage; | |
| /** | |
| * [goToNextPage description] | |
| * @return {[type]} [description] | |
| */ | |
| function goToPage() { | |
| console.log('gotoPage Called'); | |
| // Call pre-phase callback | |
| if ( !_.isUndefined(vm.prePhaseCallback) ) { | |
| vm.prePhaseCallback(); | |
| } | |
| vm.getData(); | |
| } | |
| function getData() { | |
| var promise = vm.callback(); | |
| // Call post-phase callback | |
| if ( !_.isUndefined(vm.postPhaseCallback) ) { | |
| vm.postPhaseCallback(); | |
| } | |
| return promise; | |
| } | |
| function decodeQuery(query) { | |
| return decodeURIComponent( | |
| (query + '').replace(/\+/g, '%20') | |
| ) || ''; | |
| } | |
| } | |
| angular | |
| .module('app') | |
| .controller( | |
| 'PaginationCtrl', | |
| PaginationCtrl | |
| ); | |
| })(angular, _); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| +(function(angular, _) { | |
| function pagination() { | |
| // callback is called when the data is being fetched | |
| // prePhaseCallback, called before the data is fetched | |
| // postPhaseCallback, called after the data is fetched | |
| var scope = { | |
| callback: '&', | |
| prePhaseCallback: '&', | |
| postPhaseCallback: '&', | |
| direction: '@' | |
| }; | |
| return { | |
| scope: scope, | |
| restrict: 'EA', | |
| transclude: true, | |
| template: getTemplate, | |
| controller: 'PaginationCtrl', | |
| controllerAs: 'pagination' | |
| }; | |
| /** | |
| * Simply generates the template string | |
| * @return string | |
| */ | |
| function getTemplate() { | |
| return [ | |
| '<div ng-transclude ng-click="pagination.goToPage()">', | |
| '</div>' | |
| ].join(''); | |
| } | |
| } | |
| angular | |
| .module('app') | |
| .directive('ssPagination', pagination); | |
| })(angular); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment