简体   繁体   English

Angular - 将值从 HTML 传递到组件不起作用

[英]Angular - Passing value from HTML to component does not work

In my project I am trying to pass name from .html to .ts file.在我的项目中,我试图将name.html传递到.ts文件。

In .html file I pass value to newValue method..html文件中,我将值传递给newValue方法。 In ts when I console.log the value of name , is displays nothing .在 ts 当我console.log the value of name时, displays nothing

How can I make this work?我怎样才能使这项工作?

.ts .ts

  newValue(name: string) {
  console.log(name); ------------------> displays nothing
  }

.html .html

  <dd id="{{genId(name.value)}}">
          <inline-concept-edit *ngIf="name.$new; else noValueExists" id="tane"
 [(field)]="name.value" [elementType]="record.finish"(fieldChange)="newValue(name)"></inline-concept-edit>
          <ng-template #noValueExists>
            <span *ngIf="!name.$new"
                  matTooltip="We cannot change the value"
                  [matTooltipPosition]="'right'"
                  [matTooltipDisabled]="!editMode">
              {{name.value}}
            </span>
          </ng-template>
        </dd>

Can you please mentioned what is this name ?你能说一下这个名字是什么吗? The code pasted above do not show what reference name holds.上面粘贴的代码没有显示引用名称的含义。 My guess name is not getting passed into that method when the event occurs.事件发生时,我的猜测名称没有传递到该方法中。

@Tejs Mehta. @Tejs Mehta。 you must be emitting this value from inline-cell-edit component (I assume this is your custom component).您必须从inline-cell-edit组件发出此值(我假设这是您的自定义组件)。

If yes try to console over there as well.如果是的话,也试着在那里安慰一下。

and change this line from并将这一行从

(fieldChange)="newValue(name)" to (fieldChange)="newValue($event)" (fieldChange)="newValue(name)"(fieldChange)="newValue($event)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM