无法读取角度5中的@input属性值

时间:2018-01-18 09:22:21

标签: angular typescript

我正在创建一个用于重用其代码的组件。

@Component({
    selector: 'app-jform',
    encapsulation: ViewEncapsulation.None,
    templateUrl: './jform.component.html',
    styleUrls: ['./jform.component.css']
})
export class JformComponent implements OnInit {

     @Input('init') modulename:string = '';

     ngOnInit() {
        this.getJsonForm();
        console.log(this.modulename); 
     }
}

在另一个竞争对手的视图文件中,我将此选择器的用法如下,

<app-jform [modulename]="Blue32"></app-jform>

现在我无法在控制台中将modulename作为“Blue32”。我已经导入了输入模块,我没有得到任何其他错误。

更新:根据@SurenSrapyan的建议,我更改了@Input声明。仍然以某种方式无法得到它。

现在,我在控制台中得到“未定义”。

1 个答案:

答案 0 :(得分:5)

您可以通过名称db := gorm.Open("mysql", ...) db.Set("gorm:table_options", "ENGINE=InnoDB") db.Set("gorm:table_options", "collation_connection=utf8_general_ci") // Migrate the schema db.AutoMigrate(&models.Currency{}) db.AutoMigrate(&models.Rate{}) 查看您的元素。如果您要从init删除'init'部分,则可以通过@Input('init')访问该部分。

检查

modulename

或者

@Input('init') modulename: string

<app-jform [init]="'Blue32'">
</app-jform>