輸入字段值在輸入字段中未顯示。我同時使用ng-model & data-ng-model。不使用ng-model顯示的值。使用ng-model時不顯示AngularJS輸入字段值
即1:
<input type="text" value="{{accountDetailsBody.phoneNumber}}" data-ng-model="vm.user.phoneno" name="phoneno" id="phoneno" class="form-control">
即2:
<input type="email" name="email" class="form-control" id="email" ng-model="vm.user.email" readonly ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/" placeholder="Email" ng-maxlength="30" required>
控制器
(function() {
'use strict';
angular
.module('app')
.controller('accountController', accountController);
accountController.$inject = ['ApiService', '$rootScope', 'UserService', '$scope', '$location'];
function accountController(ApiService, $rootScope, UserService, $scope, $location) {
$scope.accountDetailsBody = {};
var vm = this;
vm.userUpdate = userUpdate;
initController();
function initController() {
loadCurrentUser();
}
function userUpdate() {
console.log(vm.user);
}
function loadCurrentUser() {
$scope.data = {'email': $rootScope.globals.currentUser.username};
UserService.GetByUsername($scope.data).then(function (response) {
if (response.success) {
$scope.accountDetailsBody = response.user[0];
} else {
$location.path('/');
}
//vm.user = user;
});
}
}
})();
顯示控制器 – Sajeetharan
這是我的控制器:D –
是什麼樣的代碼這!!!!你確定這個控制器與這些輸入有關嗎? – Maher