使用angular2显示/隐藏密码文本 [英] show/hide password text using angular2

查看:79
本文介绍了使用angular2显示/隐藏密码文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据用户单击显示/隐藏密码文本.但是我收到以下错误信息:

i want to show/hide the password text based on the user click. But i am getting the following error saying:

export class App {
    password = "secret";
    show = false;

    @ContentChild(ShowHideInput) input: ShowHideInput;

    constructor(){}

    toggleShow()
    {
        this.show = !this.show;
        console.log(this.input); //undefined
        if (this.show){
            this.input.changeType("text");
        }
        else {
            this.input.changeType("password");
        }
    }
}

我创建的以下链接链接.

The following plunker link which i have created.

https://plnkr.co/edit/2GK79PuPtRQNmoUbF6xC?p=preview

推荐答案

您需要使用 ViewChild()而不是 ContentChild()

@ViewChild(ShowHideInput) input: ShowHideInput;

检查您的朋克

ContentChild()用于在已包含内容中进行匹配.例如< ng-content></ng-content>

ContentChild() is for matching inside the transcluded content. e.g. contents inside <ng-content></ng-content>

这篇关于使用angular2显示/隐藏密码文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆