This is the situation:
I am building an app with Codeigniter + Angular Js.
Right now it is a simple app that grab some data from a database and display it in a table. To build the app further i need to put the list inside a partial folder, but i am not able to load the file that need to be included.
This is the question:
How can i use partials in a Codeigniter + Angular Js project?
Where i need to put the partials folder?
This is the code:
The file index.html:
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<script src="assets/js/lib/angular.min.js"></script>
<script src="assets/js/lib/angular-route.min.js"></script>
<script src="assets/js/app.js"></script>
<script src="assets/js/controllers.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h1>Codeigniter + Angular Js App</h1>
<div class="main col-md-12" ng-view></div>
</body>
</html>
The partial file list.html:
<section>
<table class="table table-striped table-condensed table-bordered">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr ng-repeat="user in users">
<td><a href="#/user/{{user.user_id}}">{{user.name}}</a></td>
<td>{{user.year}}</td>
</tr>
</table>
</section>
This is the file app.js:
var myApp = angular.module('myApp', [
'ngRoute',
'userControllers',
]);
myApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/list', {
templateUrl: 'partials/list.html',
controller: 'ListController'
}).
otherwise({
redirectTo: '/list'
});
}]);
The file controllers.js:
var userControllers = angular.module('userControllers',[]);
userControllers.controller('ListController',['$scope','$http', function ($scope,$http)
{
// Initialising the user array.
$scope.users = [];
// Getting the list of users through ajax call.
$http({
url: 'http://127.0.0.1/Angular/4-SampleApp2/main/json_get_users',
method: "POST",
}).success(function (data) {
$scope.users= data;
});
}]);
Right now the 'partials' folder is inside the 'views' folder, and inside there is one file: list.html
The table with the list of users is not loaded anymore. Someone knows how can i load partials into a Codeigniter+Angular project? Thank you very much!
EDIT:
This is the error message in the console:
Failed to load resource: the server responded with a status of 404 (Not Found) http://127.0.0.1/Angular/4-SampleApp2/partials/list.html