【发布时间】:2016-10-26 13:09:02
【问题描述】:
我有 2 个组件导航栏和登录,我想在登录组件的导航栏中调用一个函数,到目前为止我尝试了这个但没有成功...... 我的 navbar.ts,
import {Component, OnInit} from '@angular/core';
@Component({
selector: 'header-Navbar',
templateUrl: './app/navbar/navbar.html',
})
export class Navbar implements OnInit {
constructor(public router: Router) {
}
get(){
if (this.user == null) {
this.showstartupbuttons = true;
this.showsicons = false;
}
else {
this.username = this.user.username;
this.showsicons = true;
this.showstartupbuttons = false;
}
}
我的 login.ts,
import {Component, OnInit} from '@angular/core';
@Component({
templateUrl: './app/login/login.html',
providers:[Navbar]
})
export class Login implements onInit{
ckeditorContent:any;
constructor(public navbar:Navbar) {}
ngOnInit(){
this.navbar.get();
}
我使用了提供程序,但我不确定这些过程。任何人都可以建议帮助。
【问题讨论】:
-
请参阅我的问题 - stackoverflow.com/questions/40219356/… 它的调用属性,但您可以以相同的方式调用函数。不幸的是,我遇到了一个没有解决的问题。也许你知道
标签: angular typescript