Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@cyclon2joker

angularjsでフォーム部品名がjavascriptの変数名にならない時の指定方法

タグのnameにカッコとか入ってると、変数名に直接出来ない。

<div ng-controller="LoginController as Login">
<form action="/login" id="loginForm" name="loginForm" method="post" novalidate>

  <input type="text" id="loginId" name="form[loginId]" placeholder="Login ID"
    required="true" ng-model="Login.loginId" value="" autofocus/>

  <input type="password" id="loginPwd" name="form[loginPwd]"
    placeholder="password" required="true" ng-model="Login.loginPwd" value=""/>

  <button type="button"ng-click="Login.doLogin()">Sign in</button>

</form>
</div>

上記の場合、こんな風にはかけないので、

$scope.loginForm.form[loginId].$valid

こう書く。

$scope.loginForm['form[loginId]'].$valid
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
1
Help us understand the problem. What are the problem?