0
試圖在承諾則函數使用角持久性,但總是說未定義角4持久性存儲使用則發揮作用
import { Component, OnInit, Injectable } from '@angular/core';
import {Router} from "@angular/router";
import {PersistenceService, StorageType} from "angular-persistence";
export class ProcessingComponent implements OnInit {
myfunc: any;
constructor(private PersistenceService: PersistenceService){
}
ngOnInit() {
this.myfunc = new myfunction();
this.shaObj.generateIdentity().then(function (result, PersistenceService) {
console.log(PersistenceService.set('identityKey')); // getting undefined
}.bind(this.PersistenceService));
}
所以綁定服務似乎並不奏效,如何讓外部範圍'this'被傳遞給'.then'函數。
冠軍得主,雞宴
Arrow function
的ES6美 – wesside