小编Rah*_*dev的帖子

如何在Angular 2中的本地或会话存储中存储令牌?

我想使用本地存储或会话存储中保存的身份验证令牌angular 2.0.0.我用angular2-localstorage,但它只能角2.0.0 rc.5,当我用它在2.0.0它通过我键入错误.我想使用Angular 2.0.0的默认本地存储.

local-storage angular

53
推荐指数
4
解决办法
13万
查看次数

Angular 2单元测试:无法解析Router的所有参数

我使用带有角度2的业力的单元测试.我在我的服务中添加了路由器,但是当我为此编写测试用例时,它通过我跟随错误.

 Error: Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?, ?).
Run Code Online (Sandbox Code Playgroud)

这是代码

spec.ts

import 'rxjs/add/operator/map';
import { Http, BaseRequestOptions, Response, ResponseOptions,ConnectionBackend } from '@angular/http';
import { MockBackend, MockConnection } from '@angular/http/testing';
import { GlobalUtils } from './global.utils';
import {  Router} from '@angular/router';

import { TestBed, inject } from '@angular/core/testing';



describe('Global Utils : Meta urls API', () => {
  let emptyMetaUrl = {};

  let metaUrl = {
    LOGIN: '/operator/login',
    META_API: '/meta-api'
  };

  beforeEach(()=>TestBed.configureTestingModule({

    providers: [
      Router, …
Run Code Online (Sandbox Code Playgroud)

unit-testing karma-runner angular2-routing angular

15
推荐指数
1
解决办法
1万
查看次数

等待角度2的Http响应

我在角度2中使用HTTP请求.我想在获得HTTP响应时调用下一个进程.

示例:表单中 选择选项值来自HTTP get Request.我希望表单页面正在加载,直到我收到select选项的响应.

获得功能

getSelectOptionValue(): any {
      let area_list_url = '/select_option_list/';

      this.urlGet(area_list_url).subscribe(
        (response) => {
          let data = response.text() ? response.json() : [{}];
          if (data) {
            Constant.areaList = data;
          }
        }
      );
    }
    return JSON.stringify(Constant.areaList);
  }
Run Code Online (Sandbox Code Playgroud)

GET功能

 urlGet(url: string) {

    return this._http.get(Constant.hostUrl + url, {headers: GlobalUtils.head})
      .map((res)=> {
        if (res.status === 200) {
          console.log(res);
          return res;
        } else if (res.status = 201) {
          return res;
        }
      }).catch((error)=> {
        console.log(error);

        if (error.status === 400) …
Run Code Online (Sandbox Code Playgroud)

typescript angular

5
推荐指数
1
解决办法
5万
查看次数

当应用程序打开时,React Native Firebase 推送通知不起作用

我正在使用@react-native-firebase来处理推送通知。问题是当应用程序在后台时它正在工作。如果应用程序处于前台或打开状态,则推送通知不起作用。另外,我正在使用notifee创建自定义通知。它也不起作用。

这是版本详细信息。

"@react-native-firebase/app": "^8.3.1",
"@react-native-firebase/messaging": "^7.7.2",
"@notifee/react-native": "^0.12.3",
Run Code Online (Sandbox Code Playgroud)

实施代码

componentDidMount() {
        console.log('componentDidMount App ');

        // AppState.addEventListener('change', this._handleAppStateChange);

        messaging()
            .getInitialNotification()
            .then(remoteMessage => {
                console.log('Notification caused app to open from quit state:');
                if (remoteMessage) {
                    console.log(remoteMessage.notification);
                }
            });

        const unsubscribe = messaging().onMessage(async remoteMessage => {
            console.log('A new FCM message arrived!');
            console.log(remoteMessage);
        });

        // Register background handler
        messaging().setBackgroundMessageHandler(async remoteMessage => {
            console.log('Message handled in the background!');
            console.log(remoteMessage);

        });

        messaging().onNotificationOpenedApp(remoteMessage => {
            console.log('Notification caused app to open from background state:'); …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-firebase

5
推荐指数
1
解决办法
8342
查看次数