编码解码 base64 字符串 AngularJS1 TypeScript?
encode-decode base64 string AngularJS1 TypeScript?
我正在使用带有 TypeScript 的 Angular1。我有一个简单的问题。
有什么方法可以在我使用的环境中对 base64 中的字符串进行编码解码吗?
我搜索了很多,我可以找到 this。但我不确定它是否适用于类型定义。
所以按照 https://github.com/ninjatronic/angular-base64 中的例子,但有一点 TS 修饰:
angular
.module('myApp', ['base64'])
.controller('myController', [
'$base64', '$scope',
function($base64: any, $scope : ng.IScope) {
$scope.encoded = $base64.encode('a string');
$scope.decoded = $base64.decode('YSBzdHJpbmc=');
}]);
所以我在这里所做的就是说 $base64 参数是 "any",这允许你使用常规 JS 来对抗它而不会被 TS 抱怨。您不会对其进行智能感知/类型检查,但这并不重要。正如我在评论中所说,如果你确实想针对它定义你自己的接口,你可以。即
interface Base64Encode {
encode: (source: string) => string;
decode: (encoded: string) => string;
}
我正在使用带有 TypeScript 的 Angular1。我有一个简单的问题。
有什么方法可以在我使用的环境中对 base64 中的字符串进行编码解码吗?
我搜索了很多,我可以找到 this。但我不确定它是否适用于类型定义。
所以按照 https://github.com/ninjatronic/angular-base64 中的例子,但有一点 TS 修饰:
angular
.module('myApp', ['base64'])
.controller('myController', [
'$base64', '$scope',
function($base64: any, $scope : ng.IScope) {
$scope.encoded = $base64.encode('a string');
$scope.decoded = $base64.decode('YSBzdHJpbmc=');
}]);
所以我在这里所做的就是说 $base64 参数是 "any",这允许你使用常规 JS 来对抗它而不会被 TS 抱怨。您不会对其进行智能感知/类型检查,但这并不重要。正如我在评论中所说,如果你确实想针对它定义你自己的接口,你可以。即
interface Base64Encode {
encode: (source: string) => string;
decode: (encoded: string) => string;
}