Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用@Input Angular 2在类之间传递数据_Angular - Fatal编程技术网

使用@Input Angular 2在类之间传递数据

使用@Input Angular 2在类之间传递数据,angular,Angular,我在这里是一个noob,但我需要一些帮助,我正在做一个Ionic 2应用程序,这是关于搜索的,所以我有一个主模板,我将插入一个带有结果的新模板,所以我遇到了将搜索键从de main模板传递到结果模板的问题,我尝试使用@Input,但我是一个noob,我想学习,我将非常感谢你的帮助 这是主代码App.html我的变量是“prueba”: 这是另一个模板,我在其中接收名为“recibir”的输入: 请帮助我…它不起作用,我不知道为什么构造函数中还没有输入值 改用ngOnInit()。调用ngOnIn

我在这里是一个noob,但我需要一些帮助,我正在做一个Ionic 2应用程序,这是关于搜索的,所以我有一个主模板,我将插入一个带有结果的新模板,所以我遇到了将搜索键从de main模板传递到结果模板的问题,我尝试使用@Input,但我是一个noob,我想学习,我将非常感谢你的帮助

这是主代码App.html我的变量是“prueba”:

这是另一个模板,我在其中接收名为“recibir”的输入:


请帮助我…它不起作用,我不知道为什么构造函数中还没有输入值

改用
ngOnInit()
。调用
ngOnInit()
时,将初始化组件并解析绑定

export class GettingStartedPage{
    @Input() recibir;//this the Search_key that I receive
    constructor(app: IonicApp,http: Http) {
        this.http=http;
        this.Leyes = [];
        this.url = 'http://www.##########/resultados.json?q='; 
    }

    ngOnInit() {
        alert("Recibira :" + this.recibir);
        this.buscar(this.recibir);
    }
 }
另见


我决定使用:

export class GettingStartedPage implements OnInit{

constructor(app: IonicApp,http: Http) {

this.http=http;
this.Leyes = [];
this.url = 'http://www.leybook.com/resultados.json?q='; to  
this.val = app.getComponent('searchbox').value;(<--- This gets the value directly of "searchbox" in my main template, This worked for me)
alert(this.val);
}
ngOnInit(){    
  this.buscar(this.val); 
}
}
导出类GettingStartedPage实现OnInit{
构造函数(应用程序:IonicApp,http:http){
this.http=http;
这个.Leyes=[];
this.url=http://www.leybook.com/resultados.json?q=";

this.val=app.getComponent('searchbox')。value;(“它不工作”不是很有帮助。有错误消息吗?你说的我做了,但是没有,它没有显示任何错误消息……只是它没有显示信息
export class GettingStartedPage{
    @Input() recibir;//this the Search_key that I receive
    constructor(app: IonicApp,http: Http) {
        this.http=http;
        this.Leyes = [];
        this.url = 'http://www.##########/resultados.json?q='; 
        alert("Recibira :" + this.recibir);
        this.buscar(this.recibir);
    }
 }
export class GettingStartedPage{
    @Input() recibir;//this the Search_key that I receive
    constructor(app: IonicApp,http: Http) {
        this.http=http;
        this.Leyes = [];
        this.url = 'http://www.##########/resultados.json?q='; 
    }

    ngOnInit() {
        alert("Recibira :" + this.recibir);
        this.buscar(this.recibir);
    }
 }
export class GettingStartedPage implements OnInit{

constructor(app: IonicApp,http: Http) {

this.http=http;
this.Leyes = [];
this.url = 'http://www.leybook.com/resultados.json?q='; to  
this.val = app.getComponent('searchbox').value;(<--- This gets the value directly of "searchbox" in my main template, This worked for me)
alert(this.val);
}
ngOnInit(){    
  this.buscar(this.val); 
}
}