angularjs - 如何从模式窗口更改 $scope 变量
问题描述
我的控制器中有这个函数,我将一系列数据作为参数正确接收到该函数。
$scope.changeValues = function(measure,name,valCol) {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
backdrop: 'static',
scope: $scope,
controller: function($scope, $modalInstance) {
$scope.ok = function(){
$scope.myVar = "hello";
console.log($scope.myVar);
modalInstance.close();
}
}
});};
我想在我的 $modal.window 中更改 $scope.myVar 变量的值,但是这些更改没有保存。错误在哪里?
<div class="reducedfont" ng-init="loadCtrl()">
<script type="text/ng-template" id="myModalContent.html">
<!-- template for modal -->
<div class="modal-header">
<h3 class="modal-title">{{valueName}}</h3>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">Ok</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div></script>
<p>{{myVar}}</p>
解决方案
如果你想改变
$scope.changeValues = function(measure,name,valCol) {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
backdrop: 'static',
scope: $scope,
controller: function($scope, $modalInstance) {
$scope.ok = function(){
$scope.myVar = "hello";
console.log($scope.myVar);
$modalInstance.close($scope.myVar);
}
}
})//end of $model
modalInstance.result.then(function (SelectedItem) {
setTimeout(function () {
//SelectedItem is the value return from modal controller on close and $scope.myVar is the variable in the controller where $scope.changeValues function is defined.
$scope.myVar= SelectedItem;
}, 500);
});
};//end of function
推荐阅读
- sql - 在固定开始日期的情况下跟踪动态的每周和每月销售/采购
- javascript - 删除html表格行最后一个单元格的内容
- r - 为什么我的计算没有根据日期进行汇总,而是每次都给我相同的总价值?
- ssis - 将在脚本任务中找到的文件复制到文件夹 SSIS
- php - 如何从 PHP 中的 URL 获取 POST 参数
- botframework - 如何以编程方式获取 Microsoft Bot Framework 聊天机器人应用程序的 DirectLine 机密?
- c# - 如何在 Xamarin 应用程序中初始化 IoC 容器?
- c# - C#如何将数字作为浮点数传递给函数?
- javascript - React 的 ref 的流类型
- crystal-reports - 如何为水晶报表和 sap b1 配置令牌和布局?