我设法使所有工作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) 我有解析问题,这是用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) 我有一个简单的应用程序,将新记录插入Firebase,在输入字段下方,它只列出数据库中的最后10个项目.
问题:
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) 我开始使用简单的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 $ …