在角模式弹出范围的问题 [英] Scope issues in angular modal popup
问题描述
我有我的网页上一个模式弹出。该模式弹出利用引导角库。
I have a modal popup on my page. The modal popup use bootstrap angular library.
里面的语气我有NG-模型属性的文本框,并就ok按钮preSS我想使用文本框的值的主体。
Inside the body of the modal I have a text box with ng-model attribute, and on the press of ok button I want to use that text box value.
<input type="text" data-ng-model="ProjectName" class="form-control" tab-index="1" required />
但是,当我登录到控制台的价值,我不明白这个值。
But when I log the value to console, I dont get that value.
$scope.ok = function () {
console.log($scope.ProjectName);
};
我创建了一个 plunkr用于调试此链接。请指点。
推荐答案
您有一些问题。
首先,你没有定义的模式范围的财产。默认情况下,范围设置为$ rootScope的孩子。
You have a number of issues. Firstly, you didn't define the scope property on the modal. By default, the scope is set as child of the $rootScope.
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
size: size,
scope: $scope,
resolve: {
}
});
其次,你应该设置NG-模型是一个对象的属性,否则角度会自动在子作用域为您创建的属性。
Secondly, you should set the ng-model to be the property of an object, otherwise angular will automatically create the property for you on the child scope.
控制器
var ModalDemoCtrl = function ($scope, $modal, $log) {
$scope.model = {};
...
}
标记
<div class="modal-body">
<input type="text" ng-model="model.ProjectName" />
</div>
请参阅此plunkr的工作示例: http://plnkr.co/tbVHl27D2pXia19kOjob
See this plunkr for working sample: http://plnkr.co/tbVHl27D2pXia19kOjob
这篇关于在角模式弹出范围的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!