javascript - Error with AngularJS -
i new angularjs , here facing issue. have page submit button, when click on submit modal has open , data url has present inside modal. right now, modal opens empty , not fetching data url.below code have:
index.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>
example.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'); }; };
errors iam getting after clicking on submit is:
failed load resource: server responded status of 404 (not found)
failed load resource: server responded (url using local host) status of 405 (method not allowed)
where going wrong? hope can help. in advance!!
i updated code little bit...
working fine
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'); }; };
issue return in resolve function.now fine.
thing, results set of data in array. have loop it.
Comments
Post a Comment