Answer the question
In order to leave comments, you need to log in
How to configure route and services and controller?
I'm a newbie and I'm already tired of digging the Internet! need help!!!
have a service
'use strict';
var myApp = angular.module('myApp');
myApp.factory('Mans', ['$resource',function($resource){
return $resource('/mans.json', {},{
query: { method: 'GET', isArray: true },
create: { method: 'POST' }
})
}]);
myApp.factory('Man', ['$resource', function($resource){
return $resource('/mans/:id.json', {}, {
show: { method: 'GET' },
update: { method: 'PUT', params: {id: '@id'} },
delete: { method: 'DELETE', params: {id: '@id'} }
});
}]);
'use strict';
var myApp = angular.module('myApp', ['ngRoute', 'ngResource']);
//Controller
myApp.controller("ManListCtrl", ['$scope', '$http', '$resource', 'Mans', '$location', function($scope, $http, $resource, Mans, $location) {
console.log("ManListCtrl");
$scope.mans = Mans.query();
}]);
myApp.controller("ManNewCtrl", ['$scope', '$http', '$resource', 'Mans', '$location', '$routeParams', function($scope, $http, $resource, Mans, $routeParams, $location) {
consol.log("ManNewCtrl");
}]);
myApp.controller("ManDetailCtrl", ['$scope', '$resource', 'Man', '$location', '$routeParams', function($scope, $resource, Man, $location, $routeParams) {
$scope.man = Man.show({id: $routeParams.id});
}]);
//Routes
myApp.config([
'$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.when('/mans', {
templateUrl: 'partials/man-index.html',
controller: 'ManListCtrl'
});
$routeProvider.when('/mans/:id', {
templateUrl: 'partials/man-detail.html',
controller: 'ManDetailCtrl'
});
$routeProvider.when('/mans/new', {
templateUrl: 'partials/man-new.html',
controller: 'ManNewCtrl'
});
$routeProvider.otherwise({
redirectTo: '/mans'
});
}
]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question