我正在使用带有角度(http://pineconellc.github.io/angular-foundation/)的基础模态的集成,并且在模态在关闭时发回正确信息时遇到问题:这就是我所拥有的
模态:
<script type="text/ng-template" id="dataBlockType.html">
<h4>Select Type</h4>
<select ng-model="blockTHereSelect" ng-options="type.name for type in items track by type.id">
</select>
{{blockTHereSelect.name}}
<button class="button" ng-click="ok()">OK</button>
<a class="close-reveal-modal" ng-click="cancel()">×</a>
</script>
<!-- type modal -->
其内部的控制器中的模态函数:
$scope.openModal = function () {
var modalInstance = $modal.open({
templateUrl: 'dataBlockType.html',
controller: ModalInstanceCtrl,
resolve: {
items: function () {
return $scope.dataTypes;
}
}
});
//return of modal
modalInstance.result.then(function (returnAns) {
$scope.storeTempName = returnAns;
console.log($scope.storeTempName);
//push new information from modal in
$scope.dataBlockstypes.push({id:"",name: "" , blocks: [], typeId: "" });
}, function () {
//return function if needed
});
};
模态控制器:
var ModalInstanceCtrl = function ($scope, $modalInstance, items) {
$scope.blockTHereSelect = {};
//bring in retuned list to populate modal select list
$scope.items = items;
//pass back selection
$scope.ok = function () {
$modalInstance.close($scope.blockTHereSelect);
};
//close
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};
因此,这适用于传递信息以从原始控制器填充模态(耶)。但是我似乎遇到问题的地方是传回选定的选项名称和 ID。我的想法是,如果我只是传回附加到它的模型($scope.blockTHereSelect),它就会传递和对象,然后我可以调用 .id 和 .name 。但是,它作为一个空对象返回,如果我尝试单独发送 $scope.blockTHereSelect.id 和 $scope.blockTHereSelect.name 它们返回未定义。我似乎有点难过,我认为这可能与模型或范围在模态控制器中的工作方式有关。将不胜感激任何帮助,似乎无法解决这个问题。谢谢!!