gpt4 book ai didi

javascript - AngularJS 出错

转载 作者:行者123 更新时间:2023-11-28 01:11:43 28 4
gpt4 key购买 nike

我是 AngularJS 的新手,我遇到了一个问题。我有一个带有提交按钮的页面,当我单击提交模式时必须打开并且来自 URL 的数据必须存在于模式中。现在,模式打开但它是空的并且没有从 URL 获取数据。下面是我的代码:

索引.html:

<!doctype html>
<html ng-app="plunker">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js"></script>
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script>
<script src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3>Modal</h3>
</div>
<div class="modal-body">
{{items}}
</div>
<div class="modal-footer">
<button class="btn btn-warning" ng-click="cancel()">Close</button>
</div>
</script>
<button class="btn" ng-click="open()">Submit</button>
</div>
</body>
</html>

示例.js:

angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function ($scope, $modal, $log, $http) {


//$scope.items = ['item1', 'item2', 'item3'];

$scope.open = function () {
debugger
$http.get("URL")
.success(function (response) {
debugger
$scope.items = response.data.Table;
console.log(response.Table);
});
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return $scope.items;
}
}
});
};
};
var ModalInstanceCtrl = function ($scope, $modalInstance, items) {
$scope.items = items;

$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};

点击提交后我得到的错误是:

Failed to load resource: the server responded with a status of 404(Not Found)

Failed to load resource: the server responded (url I am using for local host) with a status of 405 (Method Not Allowed)

Here is a demo plunker

这是哪里出错了?希望任何人都可以提供帮助。提前致谢!!

最佳答案

我稍微更新了你的代码......
现在它工作正常

angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function ($scope, $modal, $log, $http) {

$scope.open = function () {
$http.get("http://jsonplaceholder.typicode.com/posts")
.success(function (response) {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
resolve: {
items: function () {
return response;
}
}

});
});


};
};

var ModalInstanceCtrl = function ($scope, $modalInstance, items) {
$scope.items = items;

$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};

问题是 resolve 函数的返回。现在没问题了。
另一件事,您的结果是数组中的一组数据。所以你必须循环它。

关于javascript - AngularJS 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37428634/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com