我正在使用 Ionic
编写 HTML Web 应用程序。在尝试将 input
元素绑定(bind)到 $scope
var 时,我遇到了未定义的情况。
SignupCtrl.js:
angular.module('SUSU.controllers', [])
.controller('SignupCtrl',
function ($scope) {
/* Form entries */
$scope.signupForm = {
email: "",
emailConfirm: ""
};
});
signup.html:
<label class="item item-input">
<input type="email" placeholder="Email" ng-model="signupForm.email">
</label>
app.js:
angular.module('SUSU', ['ionic','SUSU.controllers'])
.config(function ($stateProvider, $urlRouterProvider) {
// Set and define states
$stateProvider
....
.state('tabs.signup', {
url: '/signup',
views: {
'login-tab': {
templateUrl: 'templates/signup.html',
controller: 'SignupCtrl'
}
}
});
在调试时,我注意到将文本插入电子邮件输入后,signupForm.email
的值未定义。我怎样才能绑定(bind)这两个?我做错了什么?
最佳答案
伙计们,我不敢相信我在这件事上浪费了这么多时间......
导致问题的是 type="email"
。由于某种原因它不起作用。当我将其更改为 type="text"
时,它运行流畅。
关于javascript - 在 Ionic AngularJS 中获取未定义的 ngModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27512704/