我想将变量从一个组件传递到另一个组件,并且我正在使用 @input
这是我的父组件:
@Component({
selector: 'aze',
templateUrl: './aze.component.html',
styleUrls: [('./aze.component.scss')],
providers: [PaginationConfig],
})
export class azeComponent implements OnInit {
public hellovariable: number = 100;
}
Run Code Online (Sandbox Code Playgroud)
这是父组件的模板:
<app-my-dialog [hellovariable]="hellovariable"></app-my-dialog>
Run Code Online (Sandbox Code Playgroud)
这是我的子组件:
@Component({
selector: 'app-my-dialog',
templateUrl: './my-dialog.component.html',
styleUrls: ['./my-dialog.component.css']
})
export class MyDialogComponent implements OnInit {
@Input() hellovariable: number;
constructor() { }
ngOnInit() {
console.log(hellovariable);
}
Run Code Online (Sandbox Code Playgroud)
这是子模板:
<h3>Hello I am {{hellovariable}}<h3>
Run Code Online (Sandbox Code Playgroud)
这是app.module.ts:
@Component({
selector: 'aze',
templateUrl: './aze.component.html',
styleUrls: [('./aze.component.scss')],
providers: [PaginationConfig],
})
export class azeComponent implements OnInit {
public hellovariable: number = 100; …Run Code Online (Sandbox Code Playgroud)您好,我在表中有一个带有值的 td,当单击按钮时,我已将此 td 更改为文本类型的输入。
现在我想用 td 元素的 id 更改新输入的 id,所以我有一个例外:
input.id 不是函数
这是我的代码js:
$("tr.forc td.TdbeforeForcage").each(function () {
var html = $(this).html();
var input = $('<input class="numberforce" style="width:50%" type="text" />');
var IdTd = $(this).attr("id");
input.val(html);
input.id(IdTd); // Here trying to change id of input with id of td
$(this).html(input);
if (html.indexOf(' ') > -1) {
var newValue = html.replace(' ', ' ');
$(this).find('input.numberforce').val(newValue)
}
});
Run Code Online (Sandbox Code Playgroud)