在我的模式模板我試圖用ng-model
分配一個值到我的控制器($scope.name
)的範圍,但它不能正常工作。它給了我undefined
。我究竟做錯了什麼? Plunker hereNG-模型輸入未定義
我期望模態創建它自己的作用域,並將name
放入該範圍,因爲我使用ng-model
。這似乎是模態控制器內活性,我可以輸出它細使用{{name}}
<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-body">
Name: <input type="text" ng-model="name">
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
</div>
</script>
<button class="btn" ng-click="open()">Open me!</button>
</div>
使用Javascript:不同的範圍內被創建
angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function ($scope, $modal, $log) {
$scope.open = function() {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl
});
};
};
var ModalInstanceCtrl = function ($scope, $modalInstance) {
$scope.ok = function() {
$modalInstance.close($scope.name);
alert('name was: ' + $scope.name)
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
你已經錯過了封閉的標記在輸入字段 –