加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 如何从离子2中另一个组件的模板调用组件的功能

发布时间:2020-12-17 17:28:48 所属栏目:安全 来源:网络整理
导读:我想从另一个组件的模板中调用组件的功能 离子2.我使用home.ts在我的app dashboard.html中获取一个仪表板 零件. ion-content div class="dashboardSection" a href="" (click)="fetchAllClass()" div class="header padding text-center classes common" img
我想从另一个组件的模板中调用组件的功能

离子2.我使用home.ts在我的app dashboard.html中获取一个仪表板

零件.

<ion-content> 
<div class="dashboardSection">

            <a href="" (click)="fetchAllClass()">
                <div class="header padding text-center classes common">
                    <img src="assets/images/icos_15.png" alt="Your logo here"  width="50%" height="auto"/>
                    <p class="Sectiontitle">STUDENTS</p>
                </div>
            </a></div>
</ion-content>

这是在home.ts的帮助下显示的

doLogin(event) {    
    var user1 =this.loginForm.value;
    var password = this.loginForm.controls.password.value;
    this.homeService.doLogin(user1).subscribe(
        user =>{
            this.user = user.results; 
            this.storage.set('isLoggedIn','shahjad');
            this.navCtrl.setRoot(DashboardComponent,{thing1: user });
        },err => {
            console.log(err);
        },() => console.log('login complete')

        );
}

现在,我想从仪表板组件调用学生组件功能

我创建了学生组件,如students.ts

@Component({

    selector: 'page-students',templateUrl: "./students.html"
})
export class StudentsComponent {
    dashboardItem: any;
    mode = "Observable";
    errorMessage: string;

    constructor(public fb: FormBuilder,private studentsService: StudentsService,public navCtrl: NavController,private storage: Storage,private menu: MenuController) {}

    fetchAllClass(event) {  

        alert("fd");
    }
}

解决方法

如果您的studentcomponent是仪表板的直接子项,则可以使用viewchild.

<page-student #student></page-student>

在你的组件中:

@ViewChild('student') student: StudentComponent

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读