Jef*_*f86 3 javascript angularjs ionic-framework
我刚写了那个打开模态的简单按钮.在这个模态中,我放了一个"关闭"按钮,它触发了一个运行良好的"closeLogin()"函数.我在登录表单中创建一个啤酒按钮以启动"doTestme()"功能的方式相同,但它从未启动过.请看下面:
正确触发模态的按钮:
<script id="templates/home.html" type="text/ng-template">
<ion-view view-title="Welcome">
<ion-content class="padding">
<button type="button" class="button" ng-click="login()">Log-in Test, click on the beer!</button>
</ion-content>
</ion-view>
</script>
Run Code Online (Sandbox Code Playgroud)
处理$ scope的"MainCtrl":
.controller('MainCtrl', function($scope, $ionicSideMenuDelegate, $ionicModal, $timeout) {
$scope.loginData = {};
// Create the login modal that we will use later
$ionicModal.fromTemplateUrl('templates/login.html', {
scope: $scope
}).then(function(modal) {
$scope.modal = modal;
});
// Triggered in the login modal to close it
$scope.closeLogin = function() {
$scope.modal.hide();
};
// Open the login modal
$scope.login = function() {
$scope.modal.show();
};
$scope.doTestme = function() {
alert("test ok");
};
Run Code Online (Sandbox Code Playgroud)
正确弹出的模态:
<script id="templates/login.html" type="text/ng-template">
<ion-modal-view>
<ion-header-bar>
<h1 class="title">Login</h1>
<div class="buttons">
<button class="button button-clear" ng-click="closeLogin()">Close</button>
</div>
</ion-header-bar>
<ion-content>
<form ng-submit="doLogin()">
<div class="list">
<label class="item item-input">
<span class="input-label">Username</span>
<input type="text" ng-model="loginData.username">
</label>
<label class="item item-input">
<span class="input-label">Password</span>
<input type="password" ng-model="loginData.password" style="-webkit-flex: 1 0 100px;"><button type="button" ng-click="doTestme()" class="button button-icon ion-beer" style="font-size:35px;"></button>
</label>
<label class="item">
<button class="button button-block button-positive" type="submit">Log in</button>
</label>
</div>
</form>
</ion-content>
</ion-modal-view>
</script>
Run Code Online (Sandbox Code Playgroud)
好像从未观看过ng-click,我在控制台中没有任何错误,没有办法调试这个......任何想法?
这是codepen:http://codepen.io/anon/pen/jEpNGB
你不应该在label内使用按钮.它将无法正常工作.只需将容器更改<label>为<div>
<div class="item item-input">
<span class="input-label">Password</span>
<input type="password" ng-model="loginData.password" style="-webkit-flex: 1 0 100px;">
<button type="button" ng-click="doTestme()" class="button button-icon ion-beer" style="font-size:35px;"></button>
</div>
Run Code Online (Sandbox Code Playgroud)
检查这个工作的codepen