typescript Ionic 1(Angular 1.x)后退按钮覆盖 - 打字稿版本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript Ionic 1(Angular 1.x)后退按钮覆盖 - 打字稿版本相关的知识,希望对你有一定的参考价值。

...

backButtonOverride.setup($scope, function() {
	console.log("custom BACK");
});

...
//Adapted from http://stackoverflow.com/a/36733061/114558
export class BackButtonOverrideService {
	static $inject = ["$rootScope", "$ionicPlatform"];

	constructor(private $rootScope: ng.IRootScopeService, private $ionicPlatform: ionic.platform.IonicPlatformService) {
	}

	setup($scope: ng.IScope, customBackFunction: Function) {
		var that = this;

		//Override soft back.
		var originalSoftBack = (<any> this.$rootScope).$ionicGoBack;
		(<any> this.$rootScope).$ionicGoBack = function () {
			customBackFunction();
		};

		//Override hard back.
		// registerBackButtonAction() returns a function which can be used to deregister it
		var restoreHardBack = this.$ionicPlatform.registerBackButtonAction(
			customBackFunction, 101
		);

		//Restore original back button behaviour
		$scope.$on("$destroy", function() {
			//Restore hard back.
			restoreHardBack();

			//Restore soft back.
			// framework calls $rootScope.$ionicGoBack when soft back button is pressed
			(<any> that.$rootScope).$ionicGoBack = originalSoftBack;
		});
	}
}

angular.module("app.services").service("backButtonOverride", BackButtonOverrideService);

以上是关于typescript Ionic 1(Angular 1.x)后退按钮覆盖 - 打字稿版本的主要内容,如果未能解决你的问题,请参考以下文章

使用 Typescript 的 Ionic 1 应用程序中的 Cordova 插件

使用 Ionic + TypeScript + Angular 的混合应用程序

添加滚动到顶部按钮(Ionic 2 | Typescript)

添加滚动到顶部按钮(Ionic 2 | Typescript)

typescript Ionic 1(Angular 1.x)后退按钮覆盖 - 打字稿版本

使用 Typescript 和 ionic 在嵌套数组中搜索