search

Home  >  Q&A  >  body text

javascript - angularjs中vm的意思

;
(function () {
'use strict';

angular

.module('shuichan.app.controller', [])
.controller('AppController', AppController);

AppController.$inject = ['$state', '$ionicSideMenuDelegate', 'AuthenticationServiceConstant', 'AuthenticationService'];

/* @ngInject /
function AppController($state, $ionicSideMenuDelegate, AuthenticationServiceConstant, AuthenticationService) {

// jshint validthis: true
var vm = this;

vm.$state = $state;
vm.accessLevels = AuthenticationServiceConstant.accessLevels;
vm.loggingOut = false;

vm.doLogout = doLogout;

///////////////////////

function doLogout() {

  vm.loggingOut = true;

  AuthenticationService
    .logout()
    .then(
    function (data) {
      $ionicSideMenuDelegate.toggleLeft();
      vm.$state.go('app.login');
    }
  )
    .finally(
    function () {
      vm.loggingOut = false;
    }
  );

}

};

})();

PHP中文网PHP中文网2788 days ago627

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-10 17:31:06

    John Papa的angular style guide上指view model的意思,具体解释可以看stackoverflow上John Papa的这个回答:http://stackoverflow.com/questions/16619740/angular-should-i-use-this-or-scope/19940503#19940503

    reply
    0
  • PHP中文网

    PHP中文网2017-04-10 17:31:06

    this指向了这个变量vm,这里的this应该就是这个模块

    reply
    0
  • Cancelreply