相关疑难解决方法(0)

如何在组件模板中选择元素?

有人知道如何获取组件模板中定义的元素吗?聚合物使得它真正用简单的$$$.

我只是想知道如何在Angular中实现它.

以教程为例:

import {Component} from '@angular/core'

@Component({
    selector:'display'
    template:`
     <input #myname(input)="updateName(myname.value)"/>
     <p>My name : {{myName}}</p>
    `

})
export class DisplayComponent {
    myName: string = "Aman";
    updateName(input: String) {
        this.myName = input;
    }
}
Run Code Online (Sandbox Code Playgroud)

如何从类定义中捕获por input元素的引用?

typescript angular-components angular

463
推荐指数
9
解决办法
47万
查看次数

ElementRef安全风险角度2

为什么ElementRef不安全,如果是这样,我们可以使用什么呢?

我一直在使用这个ElementRef来查看或观看特定的html标签,然后在初始化之后作为特定宽度发送,但是如果这打开了安全风险我将不会使用它,并且说实话我不明白为什么角度2个团队在他们的框架中允许这种安全漏洞.

什么是安全和最好的技术?我的测试组件如下:

        import { Component, OnInit } from '@angular/core';

        @Component({
          selector: 'app-standard',
          template: ` <button type="button" #buttonW></button>`,

        })
        export class standardComponent implements OnInit {

          name: string = 'app-standard';
          viewWidthButton: any;

          @ViewChild( 'buttonW' ) elButtonW: ElementRef; 


          constructor() { 

            this.viewWidthButton = this.elButtonW.nativeElement.offsetWidth;
            console.log ('button width: ' + this.viewWidthButton);
          }

          ngOnInit() {
          }

        }
Run Code Online (Sandbox Code Playgroud)

Angular 2页面参考:

https://angular.io/docs/ts/latest/api/core/index/ElementRef-class.html

angular

6
推荐指数
1
解决办法
1829
查看次数

在TypeScript中选择文本

如何在TypeScript中的输入字段中选择文本.

在Javascript中这个wpuld看起来像这样:

document.getElementById('id').select();
Run Code Online (Sandbox Code Playgroud)

但TypeScript不支持select(错误:[ts]属性'select'在类型'HTMLElement'上不存在.)

添加了一些想法:它可能是一个问题beacouse我使用dx控件,他们创建一个包装器.你可以在这里看到html:

<dx-text-box _ngcontent-c1="" id="test" ng-reflect-disabled="false" ng-reflect-value="0:00" class="dx-texteditor dx-widget dx-textbox">
<div class="dx-texteditor-container">
<input autocomplete="off" class="dx-texteditor-input" type="text" spellcheck="false" tabindex="0" role="textbox">
<div data-dx_placeholder="" class="dx-placeholder dx-state-invisible"></div><div class="dx-texteditor-buttons-container">
</div></div></dx-text-box>
Run Code Online (Sandbox Code Playgroud)

html select typescript

4
推荐指数
1
解决办法
3598
查看次数

标签 统计

angular ×2

typescript ×2

angular-components ×1

html ×1

select ×1