通过angularjs中的另一个元素获取元素

Hel*_*llo 2 angularjs angularjs-directive angularjs-scope

我要求在单击元素(Button)时应该更改另一个元素属性.我可以通过jquery来做.但我想忽略我的角度项目中的jquery.

在Html中,

<input type=password />
<button ngclick="changeToTxt()">Change type password to text</button>
Run Code Online (Sandbox Code Playgroud)

在控制器中,

app.controller('loginPage', function ($scope) {
   $scope.changeToTxt = function () {
     **// need to get the password element and need to change type = text.....**
   }
});
Run Code Online (Sandbox Code Playgroud)

在控制器中有没有办法(或不同/最好的方式)?或者需要为此编写指令?

K.T*_*ess 5

你可以保留两个输入来做到这一点

你可以尝试这样的事情

<input type="password" ng-model="pwd" ng-show="!showText" />
<input type="text" ng-model="pwd" ng-show="showText" />

<button ng-click="showText = !showText ">Change type password to text</button>
Run Code Online (Sandbox Code Playgroud)

这是工作的plunker