代码之家  ›  专栏  ›  技术社区  ›  Illep

将URL值从父级传递给子级

  •  1
  • Illep  · 技术社区  · 5 年前

    我正在尝试将URL值从父级传递给子级。我在利用 @input .

    浏览器控制台上打印的错误信息:

    Assertion failed: We should have an asset uri when initializing the parsing.
    

    我该怎么解决这个问题?

    父母亲组成部分ts

    this.myService.getSchoolURL().subscribe(
        
        (response) =>
        {
                  this.uri = response 
        },
        (error) => 
        {
          alert(JSON.stringify(error));
        }
      );
    

    父母亲组成部分html

    <my-child [childSchoolUrl]="uri"></my-child>
    

    小孩组成部分ts

    ''''
    constructor(private platform: Platform) {}
    @Input() public childSchoolUrl: string | undefined;
    
    
    ngAfterViewInit(): void {
       console.log("Print what came from parent "+ this.childSchoolUrl);
    
       // I will be using this URL to initialize a player. I have not shown the code here assuming 
       // it is out of scope for this question.
    }
    
    0 回复  |  直到 5 年前
    推荐文章