Reputation: 451
I 'am working in a restful web application that uses symfony2 as backend and angularjs in frontend,my problem is that I should receive json URLs with ajax,this is my code:
<script>
function PostsCtrlAjax($scope, $http)
{
$http({method: 'POST', url: 'http://localhost/onlinefacturation/web/app_dev.php/clientapi/clients.json'}).success(function(data)
{
$scope.posts = data; // response data
});
}
</script>
<div ng-repeat="post in posts" >
<ul>
<li>{{post.id}}</li>
<li>{{post.nom}}</li>
<li>{{post.prenom}}</li>
</ul>
</div>
this is the console error that I get,plus,I didn't get any data in the View:
WARNING: Tried to load angular more than once.
angular.js:11383 Error: [ng:areq] Argument 'PostsCtrlAjax' is not a function, got undefined
http://errors.angularjs.org/1.3.2/ng/areq?p0=PostsCtrlAjax&p1=not%20aNaNunction%2C%20got%20undefined
at REGEX_STRING_REGEXP (http://localhost/ProjetWeb/src/vendor/angular/angular.js:80:12)
at assertArg (http://localhost/ProjetWeb/src/vendor/angular/angular.js:1577:11)
at assertArgFn (http://localhost/ProjetWeb/src/vendor/angular/angular.js:1587:3)
at http://localhost/ProjetWeb/src/vendor/angular/angular.js:8333:9
at chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:622:22
at http://localhost/ProjetWeb/src/vendor/angular/angular.js:7507:34
at forEach (http://localhost/ProjetWeb/src/vendor/angular/angular.js:347:20)
at nodeLinkFn (http://localhost/ProjetWeb/src/vendor/angular/angular.js:7494:11)
at compositeLinkFn (http://localhost/ProjetWeb/src/vendor/angular/angular.js:6993:13)
at nodeLinkFn (http://localhost/ProjetWeb/src/vendor/angular/angular.js:7632:24)
thanks for help
update: this is the index.html:
html lang="en" data-ng-app="app" >
<head> ...... </head>
<body ng-controller="AppCtrl">
<div class="app" id="app" ng-class="{'app-header-fixed':app.settings.headerFixed, 'app-aside-fixed':app.settings.asideFixed, 'app-aside-folded':app.settings.asideFolded, 'app-aside-dock':app.settings.asideDock, 'container':app.settings.container}" ui-view></div>.........</body></html>
abd this is the file .html in which I want to get data from the json file URL:
<script>function PostsCtrlAjax($scope, $http)
{
$http({method: 'POST', url: 'http://localhost/onlinefacturation/web/app_dev.php/clientapi/clients.json'}).success(function(data)
{
$scope.posts = data; // response data
});
}
</script>
<div class="hbox hbox-auto-xs hbox-auto-sm" ng-init="
app.settings.asideFolded = false;
app.settings.asideDock = false;
" data-ng-app="app" ng-app>
<div id="ng-app" ng-app ng-controller="PostsCtrlAjax">
<div ng-repeat="post in posts" >
<ul>
<li>{{post.id}}</li>
<li>{{post.nom}}</li>
<li>{{post.prenom}}</li>
</ul>
</div>
</div></div>
Upvotes: 0
Views: 227
Reputation: 6900
Try you controller like this
app.controller('PostsCtrlAjax', ['$scope', '$http' ,function($scope,$http) {
$http({method: 'POST', url: 'http://localhost/onlinefacturation/web/app_dev.php/clientapi/clients.json'})
.success(function(data){
$scope.posts = data; // response data
});
}]);
Upvotes: 1