我刚刚开始使用角度4而不是angular.js 1.
我已经按照英雄教程了解了角度4的基本原理,我目前正在使用角度自己的"@ angular/router"包中的"RouterModule".
为了实现我的应用程序的一些授权我想知道如何手动重定向到另一条路线,我似乎无法在互联网上找到任何有用的信息.
@Component({
selector: 'bancaComponent',
templateUrl: '{{str}}'
})
export class BancaComponent implements OnInit {
str: String;
constructor(private http: Http) { }
ngOnInit(): void {
this.str = "./file.component.html";
}
Run Code Online (Sandbox Code Playgroud)
还有另一种方法吗?谢谢 :)
我目前想知道角度订阅和取消订阅。关于这个主题有很多东西,所以我对所有这些都有点迷失。
我什么时候应该取消订阅?如果我不取消订阅会发生什么?我从未遇到过 reliquat 订阅的任何错误。
有没有办法自动取消订阅组件/应用程序中的所有内容,这样我就不必通过订阅声明 1 个属性?这可能非常烦人:
@Component({
selector: 'subscriptionTest',
template: `...`,
})
export class SubTestComponent {
first;
second;
third;
constructor(private remote: RemoteService){}
ngOnInit() {
this.first = remote.getSomeData().subscribe(data => // do something);
this.second = Observable.interval(500).subscribe(event => // do something);
this.third = remote.getSomeOtherData().subscribe(data => // do something);
}
ngOnDestroy() {
this.first.unsubscribe();
this.second.unsubscribe();
this.third.unsubscribe();
}
}
Run Code Online (Sandbox Code Playgroud)