我有一个模式,其形式应该在用户点击按钮时弹出。此表单包含当前用户的信息,字段应根据其数据进行更新。问题是,他们不是。它们看起来是空的,即使ng模型变量具有不同的值。
这是HTML:
<div class="modal-header">
<h3 class="modal-title">Edit Profile</h3>
</div>
<div data-ng-controller="EditProfileCtrl">
<div class="modal-body">
<form class="form-group" name="editProfileForm" id="editProfileForm" novalidate>
<input type="hidden" name="id" ng-model="editProfileInfo.id" ng-value="editProfileInfo.id" />
<label>First Name</label>
<input type="text" class="form-control" name="firstname" ng-model="editProfileInfo.firstname" ng-value="editProfileInfo.firstname" />
<label>Last Name</label>
<input type="text" class="form-control" name="lastname" ng-model="editProfileInfo.lastname" ng-value="editProfileInfo.lastname" />
<label>Email</label>
<input type="text" class="form-control" name="email" ng-model="editProfileInfo.email" ng-value="editProfileInfo.email" />
</form>
</div>
<div class="modal-footer">
<button class="btn btn-warning" type="button" ng-click="closeModal()">Cancel</button>
<button class="btn btn-primary" type="button" ng-click="editProfile()">Edit Profile</button>
</div>
</div>
以下是Angular Controller:
angular.module('uiPoimmo')
.controller 'EditProfileCtrl', ($scope,$http,$route,$rootScope,ModalFactory,UserFactory) ->
$scope.editProfileInfo = {}
$scope.error = null
$scope.openModal = ->
ModalFactory.open('sm','editprofilemodal.html')
userInfo = $rootScope.user
$scope.editProfileInfo.id = userInfo.id
$scope.editProfileInfo.firstname = userInfo.firstname
$scope.editProfileInfo.lastname = userInfo.lastname
$scope.editProfileInfo.email = userInfo.email
ModalFactory打开模态(工作),UserFactory包含向服务器发送请求的函数。
我尝试过使用$ scope。$ apply()并将函数中的所有赋值包装起来并将其作为参数发送到$ scope.apply()......两者都没有用。我还尝试在用户通过广播登录时更改值,但它也不起作用。
对可能发生的事情的任何见解?
更新
的index.html
<!-- Code Before -->
<li class="dropdown spaced">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">MyName<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>
<!-- Ignore these changes, just leave yours -->
<a ng-controller="EditProfileCtrl" ng-click="openModal()">Profile</a>
<a ng-click="open('sm')">Saved Searches</a>
<a ng-click="open('sm')">My Estates</a>
<a ng-controller="CreateEstateCtrl" ng-click="open('lg')">Create Estate</a>
<a ng-click="open('sm')">Logout</a>
</li>
</ul>
</li>
<!-- Code After -->
<div ng-view=""></div>
<!-- Scripts -->
<!-- Modal outputs here, just before the closing body tag -->
</body>
莫代尔工厂:
angular.module('uiPoimmo')
.factory 'ModalFactory', ($uibModal,$modalStack) ->
open: (size, template) ->
return $uibModal.open(
animation: true
templateUrl: "views/#{template}"
size: size
)