我正在創建一個模式對話框,並嘗試在對話框關閉時讀取字段,但是當編輯輸入時,輸入字段的ng模型是被設置爲未定義。使用Plunk,如果您單擊對話框按鈕,然後在不修改文本字段的情況下按確定,它將顯示「blah」。但是,如果您根本不修改文本輸入,則不會顯示任何內容。在編輯時將ng-model設置爲undefined
對話框模板是:
<script type="text/ng-template" id="simpleModal.html">
<div class="modal-header">
<h3 class="modal-title">Simple Modal</h3>
</div>
<div class="modal-body">
<div class="form-group">
<label for="emailInput">Email</label>
<input id="emailInput" type="email" class="form-control" ng-model="user.email">
</div>
</div>
<div class="modal-footer">
<button class="btn" type="button" ng-click="ok()">Ok</button>
</div>
</script>
而且控制器爲模態對話框:
app.controller('SimpleModalController', function($scope, $uibModalInstance, $log) {
$scope.user = {
email: "blah"
};
$scope.ok = function() {
$log.debug('simpleModal ok called ' + $scope.user.email);
$uibModalInstance.close($scope.user.email);
};
});
我見過參考https://stackoverflow.com/a/22768720/552936,但我已更改我的代碼以反映此問題,但尚未解決問題。
類型是電子郵件 - 如果你鍵入一個有效的電子郵件的作品。如果它不是一個有效的電子郵件,它將是未定義的。 – Etse