我正在使用jsonp加载下拉列表,从网址填充下拉列表,但是当我选择选项1时,它应该打开一个包含一些规则的对话框。我正努力做到这一点,但没有运气。
我正在关注ui-bootstrap模态代码和stackoverflow
<div class="table-cell" ng-app="ui.bootstrap.demo" ng-controller="ModalDemoCtrl">
<select id="method" ng-change="open();" ng-model="selected">
<option>
--select--
</option>
<option ng-repeat="item in items" value={{item.id}}>{{item.value}} </option>
</select>
</div>
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">Results <small>Total Records: <strong>{{allrecords.length}}</strong></small></h3>
</div>
<div class="modal-body">
<p>Your selection: {{selected}}</p>
<p>Displaying records: {{startval}} - {{endval}}</p>
<ol start="{{startval}}">
<li ng-repeat="record in allrecords.slice(startval-1, endval)">{{record.Name}}</li>
<ol>
</div>
<div class="modal-footer">
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>
角
// Code goes here
var app = angular.module('ui.bootstrap.demo', ['ui.bootstrap']),
dropDown = angular.module('ui.bootstrap.demo', []);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function($scope, $uibModal, $log) {
console.log($scope);
$scope.animationsEnabled = true;
$scope.open = function(size) {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: size,
resolve: {
items: function() {
return $scope.items;
}
}
});
modalInstance.result.then(function(selectedItem) {
$scope.selected = selectedItem;
}, function() {
$log.info('Modal dismissed at: ' + new Date());
});
};
$scope.toggleAnimation = function() {
$scope.animationsEnabled = !$scope.animationsEnabled;
};
});
// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $uibModal service used above.
angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function($scope, $uibModalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function() {
$uibModalInstance.close($scope.selected.item);
};
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
});
dropDown.controller('ModalDemoCtrl', function($scope, $http) {
$http({
method: 'JSONP',
url: 'URL?callback=JSON_CALLBACK',
withCredentials: true
}).then(function successCallback(response) {
console.log(response.data);
return response.data;
}, function errorCallback(response) {
console.log(response);
});
});