我来自NG1环境,目前我正在创建具有所有可用功能的NG2应用程序.在问我之前我正在探索google和stackoverflow问题,但没有运气,因为angular 2移动得如此之快,api架构和大多数答案都已过时.
我的情况:我有属性用户的Auth提供者(服务),我想观察用户并对多个组件做出反应(导航栏,侧栏等)
我尝试了什么:
@Injectable();
export class Auth {
private user;
authorized: EventEmitter<boolean>;
constructor(public router:Router){
this.authorized = new EventEmitter<boolean>();
}
login(user, token):void{
localStorage.setItem('jwt', token);
this.user = _.assign(user);
this.authorized.emit(<boolean>true);
this.router.parent.navigateByUrl('/');
}
}
/***************/
@Component({...})
export class NavComponent {
public isAuthroized: boolean = false;
constructor(Auth:Auth){
Auth.authorized
.subscribe((data) => this.onUserChanged(data));
}
onUserChanged(user){
alert('USER:' + user.email);
this.isAuthroized = true;
}
}
/****************/
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
ELEMENT_PROBE_PROVIDERS,
HTTP_PROVIDERS,
MapLoader,
Auth
])
Run Code Online (Sandbox Code Playgroud)
但没有运气.我应该使用Observable EventEmitter还是有其他正确的方法来处理这种情况?在NG1中,它就像在服务的属性上设置$ watch一样简单.谢谢!
编辑:我为Auth服务添加了新方法:
...
userUpdated: EventEmitter<boolean>;
constructor(public router:Router){
this.userUpdated = new EventEmitter<any>();
} …Run Code Online (Sandbox Code Playgroud) 我已经使用 React Viro 两年了。它在 Android 和 iOS 上都运行得相当稳定。最后,Viro 放弃了官方支持,将存储库移至社区,从这时起它开始成为一场噩梦。已弃用的 API、商店拒绝等。作为一名 JavaScript 开发人员,我的手很紧,因此如果不花几个月的时间学习新的 Google Cardboard API 和 Objective-C 内容,我就无法修补它。
我的一位客户只使用 VR,所以我现在不关心 AR。我们还有其他选择吗(付费的也可以)?我正在寻找稳定的、最新的并且可以在未来两年内使用的东西。React Native 是否有任何本机端口?
提前致谢