我正在使用Themeforest-Template,其中控制器如下所示:
(function () {
"use strict";
angular.module("app.tables", []).controller("articlesCtrl", ["$scope", "$http",
function ($scope, $http) {
$http.get('www/articles.php?method=fetchAll').success(function (data) {
$scope.articles = data;
console.log($scope.articles);
}).
error(function (data) {
// log error
})
}
])}.call(this))
在网络的任何地方,我都找到了控制器看起来像这样的指南和教程:
app.factory('articlesFactory', function ($http, $resource) {
$http.get('www/articles.php?method=fetchAll').success(function (data) {
return $resource(data);
});
app.controller('articlesCtrl', function ($scope, articlesFactory) {
$scope.articles = articlesFactory.query();
})});
为什么这对我不起作用?
我的app.js看起来像这样:
(function () {
'use strict';
angular.module('app', [
'ngRoute',
'ngAnimate',
'ui.bootstrap',
'easypiechart',
'textAngular',
'ui.tree',
'ngMap',
'ngTagsInput',
'app.controllers',
'app.directives',
'app.directives',
'app.localization',
'app.nav',
'app.ui.ctrls',
'app.ui.directives',
'app.ui.services',
'app.ui.map',
'app.form.validation',
'app.ui.form.ctrls',
'app.ui.form.directives',
'app.tables',
'app.task',
'app.chart.ctrls',
'app.chart.directives',
'app.page.ctrls',
'app.calls',
'app.avgLic'
]).config([
'$routeProvider', function ($routeProvider) {
var routes, setRoutes;
routes = [
"calls/calls",
"calls/archive",
"calls/statistics",
"calls/sms",
"contacts/contacts",
"configurator/configurator",
"configurator/offers",
"configurator/search",
"configurator/articles",
"configurator/orders",
"configurator/distributors",
"orders/new_orders",
"orders/archive",
"avg/active_lic",
"avg/new_lic"
];
setRoutes = function (route) {
var config, url;
url = '/' + route;
config = {
templateUrl: 'views/' + route + '.html'
};
$routeProvider.when(url, config);
return $routeProvider;
};
routes.forEach(function (route) {
return setRoutes(route);
});
return $routeProvider.when('/', {
redirectTo: '/calls/calls'
}).when('/404', {
templateUrl: 'views/pages/404.html'
}).otherwise({
redirectTo: '/404'
});
}
]);}).call(this);