Javascript 在angular 8中使用@input decorator将数据从父组件传递到子组件
您好,我想将一个数字从一个组件传递到另一个组件,我正在使用@input 这里是我的父组件:Javascript 在angular 8中使用@input decorator将数据从父组件传递到子组件,javascript,html,angular,angular-decorator,Javascript,Html,Angular,Angular Decorator,您好,我想将一个数字从一个组件传递到另一个组件,我正在使用@input 这里是我的父组件: @Component({ selector: 'inter-asp', styleUrls: [('./asp.component.scss')], templateUrl: './asp.component.html', template: '<app-my-dialog [hellovariable]="hellovariable"></app-my
@Component({
selector: 'inter-asp',
styleUrls: [('./asp.component.scss')],
templateUrl: './asp.component.html',
template: '<app-my-dialog [hellovariable]="hellovariable"></app-my-dialog>',
providers: [PaginationConfig],
})
export class aspComponent implements OnInit {
public hellovariable: number = 100;
}
@Component({
selector: 'app-my-dialog',
templateUrl: './my-dialog.component.html',
styleUrls: ['./my-dialog.component.css']
})
export class MyDialogComponent implements OnInit {
@Input() hellovariable: number;
}
在子组件中,我想显示从父组件传递的变量HelloVorable的内容,但我没有定义它,所以这里有什么问题。它优先于模板url,删除该部分并将其作为
@Component({
selector: 'inter-asp',
styleUrls: [('./asp.component.scss')],
template: '<app-my-dialog [hellovariable]="hellovariable"></app-my-dialog>',
providers: [PaginationConfig],
})
@组件({
选择器:“inter asp”,
样式URL:[('./asp.component.scss'),
模板:'在父模板中,必须将输入作为子组件的属性传递给子组件
<app-child-component [prop]="prop"></app-child-component>
@Sajeetharan MSFT不理解您在父组件中打印它的意思您有templateUrl和template。您需要删除它one@mecabmecab95检查这个链接解决同样的问题我想它对你有帮助@Abhishek谢谢现在我确实喜欢你的例子,但我在我的父组件中有一个问题寻找这个问题我做了,但是子组件中的变量仍然未定义检查上面的演示当我放入父组件时,我在chrome中得到一个错误无法绑定到“Hellovable”,因为它不是“app-my-dialog”的已知属性检查演示。我确实喜欢演示,但在我的父组件模板页面html中的chrome中得到错误