【发布时间】:2016-11-18 00:33:18
【问题描述】:
这是我的控制器代码。显示一个弹出窗口并单击按钮,进行一些验证:
UZCampusWebMapApp.controller('PlanCtrl',function($scope, $ionicModal, $ionicLoading, $ionicPopup) {
$scope.confirmCreatePOI = function(data) {
var myPopup = $ionicPopup.show({
templateUrl: 'templates/pois/confirmCreatePOI.html',
title: 'Confirmar creación de POI',
scope: $scope,
buttons: [
{
text: '<b>Save</b>',
onTap: function() {
var invalidEmail = $scope.email.length==0 || $scope.email==null || typeof($scope.email)=='undefined';
if ($scope.emailChecked==true && invalidEmail) {
$ionicLoading.show({ template: 'Email is mandatory'});
}
else {
data.email = $scope.email;
$scope.finalSubmitCreatePOI(data);
}
}
},
{
text: 'Cancel'
}
]
});
};
});
这是调用前一个控制器函数confirmCreatePOI的指令代码:
UZCampusWebMapApp.directive('formCreatePointOfInterest', function($ionicLoading) {
return {
restrict : 'A',
scope: true,
controller : function($scope) {
$scope.submit = function(data) {
console.log("Submit form createpoint of interest",data);
if($scope.createPOIform.$valid) {
$scope.confirmCreatePOI($scope.data);
} else {
$ionicLoading.show({ template: 'El formulario es inválido', duration: 1500})
}
}
}
}
});
这是我的 templateUrl 代码:
<div id="confirm-create-poi-popup">
<p> Text </p>
<p> Text </p>
<div class="list">
<ion-checkbox ng-model="emailChecked">Receive notification</ion-checkbox>
<label class="item item-input">
<input type="email" ng-model="email">
</label>
</div>
</div>
所以,在用户点击'Save'按钮(onTap事件)后,我想检查是否在输入字段中输入了电子邮件。
但是当我检查它时:
var invalidEmail = $scope.email.length==0 || $scope.email==null || typeof($scope.email)=='undefined';
$scope.email.length==0 表达式返回错误,因为电子邮件未定义,所以ng-model 属性不适用于$scope,我在$scope.email 上没有得到任何值
这是为什么呢? $ionicPopup $scope 属性不起作用吗?用错了吗?
【问题讨论】:
标签: javascript angularjs ionic-framework angular-ngmodel