相关疑难解决方法(0)

Angular2:子组件访问父类变量/函数

我在父组件中有一个可能由child更改的变量,parent将在视图中使用此变量,因此必须传播更改.

import {Component, View} from 'angular2/core';

@Component({selector: 'parent'})
@View({
    directives: [Child],
    template: `<childcomp></childcomp>`
})
class Parent {
    public sharedList = new Array();
    constructor() {
    }
}


@Component({selector: 'child'})
@View({template: `...`})
class Child {
    constructor() {
        //access 'sharedList' from parent and set values
        sharedList.push("1");
        sharedList.push("2");
        sharedList.push("3");
        sharedList.push("4");
    }
}
Run Code Online (Sandbox Code Playgroud)

angular

64
推荐指数
3
解决办法
10万
查看次数

Angular 2 - 子组件如何与父组件对话?

Angular 2 - 子组件如何与父组件对话?

我将@input 用于父对子,效果很好。

我会用什么来做孩子对父母?

这是我得到的编译器错误:

在此处输入图片说明

angularjs angular

4
推荐指数
1
解决办法
2752
查看次数

如何从另一个ts文件更新component.ts文件中的vaiable

最初我的app.component.ts文件被加载然后我有两个变量,nameemail从API获取调用更新,为了进行此api调用我需要用户名如果​​我没有用户名我将无法更新此名称和电子邮件.

一旦我获得了用户名,我就可以拨打api电话,但我的用户名只有在登录成功后才可用.

我的app.html有这个,下面的代码是我的sidemenu的一部分

<ion-item class="profile-info">
  <ion-icon name="person" item-left></ion-icon>
  <h2>{{name}}</h2>
  <p class="se-email">{{email}}</p>
</ion-item>
Run Code Online (Sandbox Code Playgroud)

我的app.component.ts文件有这个

name 
 email

 if(localStorage.getItem("username")){
   //here it is invoking 2nd time because i have stored the username after login so no problem
    this.getUserDetails();//this function call the same api 
  }else{
    //at first thime i am not able update the name and email because i dont have username 
    //so i am trying to update the name with set and get method where it will return my data …
Run Code Online (Sandbox Code Playgroud)

ionic2 ionic3 angular

1
推荐指数
1
解决办法
1992
查看次数

标签 统计

angular ×3

angularjs ×1

ionic2 ×1

ionic3 ×1