Javascript 我可以使用角度组件选择器作为该组件的属性吗?
比如说,Javascript 我可以使用角度组件选择器作为该组件的属性吗?,javascript,angular,data-binding,angular-components,Javascript,Angular,Data Binding,Angular Components,比如说, @Component({ selector: 'editor', //Same as component input templateUrl: './editor.component.html', styleUrls: ['./editor.component.scss'] }) export class Editor implements OnInit { @Input() editor: string; //S
@Component({
selector: 'editor', //Same as component input
templateUrl: './editor.component.html',
styleUrls: ['./editor.component.scss']
})
export class Editor implements OnInit {
@Input() editor: string; //Same name as selector
@Input() color: string;
constructor() { }
ngOnInit() {
}
}
HTML:
到目前为止,我的经验是这不起作用。有没有人对如何实现这一目标有什么想法?或者如果可能的话?您应该在div标记上使用属性绑定
[editor]="value"
有可能,您应该将选择器括在方括号中
import { Component, OnInit, Input } from "@angular/core";
@Component({
selector: '[editor]', //Same as component input
template: `<span>Foo Bar template</span>`,
})
export class TryComponent implements OnInit {
@Input() editor: string; //Same name as selector
@Input() color: string;
constructor() { }
ngOnInit() {
console.info(this.editor);
}
}
import{Component,OnInit,Input}来自“@angular/core”;
@组成部分({
选择器:'[editor]',//与组件输入相同
模板:`Foo-Bar-template`,
})
导出类TryComponent在init上实现{
@Input()编辑器:string;//与选择器同名
@Input()颜色:字符串;
构造函数(){}
恩戈尼尼特(){
console.info(this.editor);
}
}
然后像这样使用
<div [editor]="'FooBarValue'" color="blue"></div>
或
你试过[编辑]
吗?你会翻译成,是的,这是可能的啊,我成功了,谢谢大家
<div [editor]="classProperty" color="blue"></div>