小编Mil*_*vic的帖子

Angular2 cookie而不是localstorage

我设法使所有工作JWT认证,没有问题,但它只支持现代浏览器,我需要Auth工作从IE9及以上开始.

我找不到任何关于如何在Angular2中使用cookie的信息或示例.有一个使用localStorage来保存令牌的简单示例,我需要相同的功能,但使用cookie.

任何帮助都会很棒,因为网上没有任何内容.

this.http.post("http://localhost:3001/sessions/create", creds, { headers: header })
    .map(res => res.json())
    .subscribe(
      data => localStorage.setItem('id_token',data.id_token),
      err => this.logError(err),
      () => console.log("Auth is completed!")
    );
Run Code Online (Sandbox Code Playgroud)

javascript cookies html5 angular

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

Angular2使用带有正斜杠的对象键上的Elvis运算符

我有解析问题,这是用Elvis运算符解决的,但是如果我有包含正斜杠的键,我就不能使用Elvis运算符,因为我必须将该键放入方括号中.

如果键很简单就可以工作("firstname")

{{ data?.record?.firstname }}
Run Code Online (Sandbox Code Playgroud)

如果key有这样的前括号("name/first"),则不起作用

{{ data?.record?['name/first']}}
Run Code Online (Sandbox Code Playgroud)

如果我使用方括号,似乎Elvis不可用.

任何解决方法?也许是一种逃避冲突的方法.这样的符号:

{{ data?.record?.name\\/first }}
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular

6
推荐指数
1
解决办法
2207
查看次数

angular2 firebase实时更新无法正常工作

我有一个简单的应用程序,将新记录插入Firebase,在输入字段下方,它只列出数据库中的最后10个项目.

问题:

  1. 我需要开始输入某些输入字段或点击"更新"以获取Firebase中的数据以显示在我的列表中.看来,在处理完角度后数据已经完成,现在它已经初始化地显示了列表.我尝试将"| async"添加到ngFor,但不起作用并导致控制台出错.一切都运行良好,只需要加载并显示数据onload,而无需在输入中输入击键或单击更新按钮.
  2. 当我用相同的应用程序打开两个选项卡时,它们不会实时更新,因为我认为一旦我开始从一个选项卡到另一个选项卡输入数据zig-zag,我只会出现在我插入数据的选项卡中.

import {Component,enableProdMode} from 'angular2/core'; enableProdMode();
import {FirebaseService} from 'firebase-angular2/core';
var myFirebaseRef = new Firebase("https://xxx.firebaseio.com/messages");

@Component({
    selector: 'my-app',
    template: `
        <input type=text [(ngModel)]="newmsg" #newmsgref (keyup.enter)="updateHello(newmsgref)">
        <button (click)="updateHello(newmsgref)">Update</button>
        <ul>
            <li *ngFor="#item of items">
              {{item}}
            </li>
        </ul>
    `
})
export class AppComponent {
    newmsg:string;
    items:Array<string>=[];

    constructor() {
        myFirebaseRef.limitToLast(10).on('child_added', (childSnapshot, prevChildKey) => {
            childSnapshot.forEach((records) => {
              this.items.push(records.val());
            });
        });
    }

    updateHello(r){
        myFirebaseRef.push({
            title: this.newmsg
        });
        this.newmsg="";
        r.focus();
    }
}
Run Code Online (Sandbox Code Playgroud)

解决方案#1与NGZONE手动更新工作(感谢:GünterZöchbauer)由于定义超出了A2,因此使用NgZone非常简单并且可以解决问题.谢谢Günter;)

import {Component,enableProdMode,NgZone} from 'angular2/core'; enableProdMode();
import {FirebaseService} from …
Run Code Online (Sandbox Code Playgroud)

firebase angular

5
推荐指数
2
解决办法
1860
查看次数

angular2失败的lodash导入

我开始使用简单的Angular 2应用程序.但是当我添加lodash的导入并尝试使用它时,我得到错误并且应用程序停止工作,并且无法弄清楚问题是什么.

我在控制台中收到这两个错误:

未捕获的SyntaxError:意外的令牌<__ exec @system.src.js:1374entry.execute @system.src.js:3300linkDynamicModule @system.src.js:2921link @system.src.js:2764execute @system.src.js:3096doDynamicExecute @ system.src.js:715link @system.src.js:908doLink @system.src.js:569updateLinkSetOnLoad @system.src.js:617(匿名函数)@system.src.js:430run @ angular2-polyfills.js: 138zoneBoundFn @ angular2-polyfills.js:111lib $ es6 $ promise $$ internal $$ tryCatch @ angular2-polyfills.js:1511lib $ es6 $ promise $$ internal $$ invokeCallback @ angular2-polyfills.js:1523lib $ es6 $ promise $ $ internal $$ publish @ angular2-polyfills.js:1494(匿名函数)@ angular2-polyfills.js:243run @ angular2-polyfills.js:138zoneBoundFn @ angular2-polyfills.js:111lib $ es6 $ promise $ asap $$ flush @ angular2-polyfills.js:1305 angular2-polyfills.js:138

未捕获的SyntaxError:意外的令牌<评估http:// localhost:3000/lodash 加载http:// localhost:3000/app/app.jsrun @ angular2-polyfills.js时出错:138zoneBoundFn @ angular2-polyfills.js:111lib $ es6 $ …

javascript ecmascript-6 angular

3
推荐指数
1
解决办法
6057
查看次数