我有一个angular2应用程序,我希望用户能够在浏览器中下载和打开pdf文件.
我可以使用angular2模块或组件吗?
如何在Angular2中显示日期时间?
{{DTE}}
它打印日期2014-10-10T11:42:28.000Z
虽然我需要它打印像
2015年10月10日
这是我的代码,给出错误无法读取属性标题undefined.
父组件
import { Child } from './child.component';
@Component({
selector: 'parent',
})
export class ParentComponet implements OnInit, AfterViewInit {
constructor(){}
@ViewChild(Child) child: Child;
ngAfterViewInit(){
console.log("check data", this.child.title)
}
}
Run Code Online (Sandbox Code Playgroud)
和儿童组件是.
@Component({
selector: 'child',
})
export class ChildComponet {
public title = "hi"
constructor(){}
}
Run Code Online (Sandbox Code Playgroud)
routing.module.ts就像
{
path: "",
component: ParentComponent,
children: [
{
path: '/child',
component: ChildComponent
}
]
}
Run Code Online (Sandbox Code Playgroud)
并且给出了错误
ERROR TypeError: Cannot read property 'title' of undefined(…)
Run Code Online (Sandbox Code Playgroud) 如何将之前的路线作为 Angular 中的路径?
我尝试通过此链接使用解决方案,但它不会在首页加载时执行。
constructor(router: Router) {
router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe((event: NavigationEnd) => {
console.log('prev:', event.previousUrl);
this.previousUrl = event.url;
});
}
Run Code Online (Sandbox Code Playgroud)
我使用了RoutesRecognized和NavigationEnd,但是它们不起作用。
我在 constructor 和中调用了这个方法ngOnInit,但是它们都没有在首页加载时执行。
有没有办法获取之前的URL?
谢谢。