ng-click inside label does not work
Asked Answered
B

1

9

<ion-view>
	<div class="bar bar-header bar-dark">
		<h1 class="title">Welcome</h1>
	</div>
	<ion-content class="has-header">
		<form ng-submit="doLogin()">
			<div class="list">
				<label class="item item-input">
					<span class="input-label">手机号</span>
					<input type="text" ng-model="phonenumber" placeholder="这里输入手机号" maxlength="11">
					<button class="button button-dark" style="margin-right: 16px;" ng-click="getVerifyCode(111)">获取验证码</button>
				</label>
				<label class="item item-input">
					<span class="input-label">验证码</span>
					<input type="password" ng-model="verifycode">
				</label>
				<label class="item">
					<button class="button button-block button-dark" ng-click="getVerifyCode(111)">登 陆</button>
				</label>
			</div>
		</form>
	</ion-content>
</ion-view>
  1. why the button(获取验证码) inside label tag doesnt work?

  2. but the button(登 陆) outside label tag work fine, why?

  3. please help me to fixed this. I need to make a response when click the button(获取验证码)

Bracken answered 13/11, 2015 at 6:0 Comment(3)
simply use <div> instead. Found info related to this issue from official Ionic framework website: forum.ionicframework.com/t/buttons-inside-form-labels/29033/2Excurvate
thanks man, It work fine.Bracken
Glad to hear it works :)Excurvate
E
16

working demo

The solution is simply not to use a label for the item. Instead just use a div

html

<form ng-submit="doLogin()">
        <div class="list">
            <div class="item item-input">
                <span class="input-label">手机号</span>
                <input type="text" ng-model="phonenumber" placeholder="这里输入手机号" maxlength="11">
                <!-- <input ></input> -->
                <button class="button button-dark" style="margin-right: 16px;" ng-click="getVerifyCode(111)">获取验证码</button>
            </div>
            <label class="item item-input">
                <span class="input-label">验证码</span>
                <input type="password" ng-model="verifycode">
            </label>
            <label class="item">
                <button class="button button-block button-dark" ng-click="getVerifyCode(111)">登 陆</button>
            </label>
        </div>
</form>
Employment answered 13/11, 2015 at 7:1 Comment(1)
@ChenzhaoWudics:Glad to help youEmployment

© 2022 - 2024 — McMap. All rights reserved.