如何在角度5中使用正在使用的组件方法?

时间:2018-07-28 05:41:27

标签: angular

在我的项目中,我想使用服务中组件的方法。我想在AdminService中调用AdvisorComponent的ngOnInit()。服务是这样的:

import {AdminAdvisorListComponent} from "../components/admin- 
components/admin-advosor-list/admin-advisor-list.component";

@Injectable()
export class AdminService {

public token: string;
public headers: any;

constructor(private http: Http,
          private apiService: ApiService,
          private adminAdvisorList: AdminAdvisorListComponent) {}

initializeAdvisorPage() {
this.adminAdvisorList.ngOnInit();
 }
}

,AdminAdvisorListComponent代码为:

import {AdminService} from '../../../services/admin.service';

export class AdminAdvisorListComponent implements OnInit {
constructor(private adminService: AdminService){}
ngOnInit(): void {
    this.adminService.getAdvisorList().subscribe(
        res => {
            if (res) {
                this.users = res;
            }
        });
}

使用这些代码会出错

  

无法解析AdminAdvisorListComponent的所有参数:(?,[对象对象],[对象对象],[对象对象],[对象对象])。   我该怎么办?   感谢您提供高级帮助。

0 个答案:

没有答案