【发布时间】:2015-11-17 12:54:04
【问题描述】:
所以我用 angular 创建了一个小工厂来获取我的本地 json 文件,现在我想将该数据传递给我的控制器,但它找不到工厂名称并显示“未解析的变量”。
这是我的代码的 sn-p,我猜现在是相关的。
(function () {
var app = angular.module('locatieTool', ['ngRoute']);
app.controller('teamController', function ($scope) {
function init () {
dataFactory.getTeams().success(function(data) {
$scope.teams = data
});
}
init();
console.log($scope.teams);
});
// factory
app.factory('dataFactory', function($http) {
var team = {};
//get local data
team.getTeams = function() {
return $http.get ('http://localhost:4040/');
};
return team;
});
})();
我的目标只是对 $scope.teams 进行控制台记录,而不是对数据做更多的事情。
【问题讨论】:
标签: angularjs angularjs-scope angular-controller