Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // BEGIN: This works!
- /**
- * Account Institutions Controller.
- * @param {angular.service.$scope} $scope Angular $scope service.
- * @param {angular.service.$http} $http Angular $http service.
- */
- function institutions($scope, $http) {
- console.log('Yaba.app.controller(institution).load()');
- $scope.institutions = [{}];
- $scope.institution = Yaba.models.EMPTY_Institution;
- $http({
- method: 'GET',
- url: '/api/institutions'
- }).then(function(response) {
- $scope.institutions = response.data.institutions;
- });
- $scope.addMapping = function addMapping() {
- $scope.institution.mappings.push({
- fromField: null,
- toField: null,
- mapType: null
- });
- };
- }
- // END: This works!
- // BEGIN: This fails
- class Institution {
- constructor(services) {
- services.hasOwnProperty('$http') && ( this.$http = services.$http );
- services.hasOwnProperty('$scope') && ( this.$scope = services.$scope );
- }
- /**
- * Query for an institution, many institutions and get more details in list format.
- * @returns Object<Institution>
- */
- async load() {
- var result = await this.$http({
- method: 'GET',
- url: '/api/institutions'
- });
- this.$scope.institutions = result.data.institutions;
- return result.data.institutions;
- }
- }
- /**
- * Account Institutions Controller.
- * @param {angular.service.$scope} $scope Angular $scope service.
- * @param {angular.service.$http} $http Angular $http service.
- */
- function institutions($scope, $http) {
- var bank = new Yaba.models.Institution({
- $scope: $scope,
- $http: $http
- });
- console.log('Yaba.app.controller(institution).load()');
- bank.load();
- $scope.institution = Yaba.models.EMPTY_Institution;
- $scope.addMapping = function addMapping() {
- $scope.institution.mappings.push({
- fromField: null,
- toField: null,
- mapType: null
- })
- };
- }
- // END: This fails.
- // Why?!?!
Advertisement
Comments
-
- https://ivantanev.com/async-functions-and-angularjs-1-x-do-not-mix/
- This is why, makes sense now. AngularJS needs to track all async events.
Add Comment
Please, Sign In to add comment