【发布时间】:2019-03-23 13:18:09
【问题描述】:
此代码是使用 angularJS 和 Bootstrap 3.1.1 编写的。
相关的 HTML 代码:
<a href="" ng-hide="readonly" ng-click="chooseChemicalPopup(stepIndex,$index)">
{{constituent.chemical.name}}
<span ng-show="constituent.chemical.name">(edit)</span>
<span ng-hide="constituent.chemical.name>(click to choose) </span>
</a>
作为“ng-click”结果调用的 JavaScript 函数:
$scope.chooseChemicalPopup = function (stepIndex, constituentIndex) {
var modalInstance = $uibModal.open({
templateUrl: '/views/templates/pick-chemical-popup.html',
controller: 'ChooseChemicalPopupCtrl',
size: '',
resolve:
{
chemicals: function () {
return $scope.chemicals;
},
selected: function ()
{
return {
chemical: $scope.record.steps[stepIndex].constituents[constituentIndex].chemical
};
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.record.steps[stepIndex].constituents[constituentIndex].chemical = selectedItem;
});
});
控制器:
angular.module('cpdApp').controller(
'ChooseChemicalPopupCtrl', function($scope, $uibModalInstance,chemicals,selected) {
$scope.chemicals = chemicals;
$scope.selected = selected;
$scope.ok - function() {
$uibModalInstance.close($scope.selected.chemical);
};
$scope.cancel = function() {$uibModalInstance.dismiss('cancel'); };
});
我在 JavaScript 函数中设置了一个断点。函数 chooseChemicalPopup 确实执行,但 ChooseChemicalPopupCtrl 不执行,并且弹出 HTML 永远不会发生。有没有人看到任何明显的东西?我继承了这段代码,所以我无法真正回答任何“为什么”。我会告诉你,这段代码中恰好调用了两个弹出窗口,但都没有出现。 chooseChemicalPopup 和 ChooseChemicalPopUpCtrl 都在同一个 Javascript 文件中。我之前发布过这个,没有提到似乎永远不会执行的控制器,现在我修改了帖子以添加这个问题。 谢谢你的时间。我对 AngularJS 或 Bootstrap 不是很流利,所以没有问题太明显而无法指出。
【问题讨论】:
标签: javascript html angularjs twitter-bootstrap-3 popup