Rog*_*che 7 javascript coffeescript angularjs
我建立一个应用程序来动态地从数据库中AngularJS加载和显示数据,但是当我尝试访问我的API(使用$ HTTP()或$ http.get()),我收到errrors.$ http.get()错误:TypeError: undefined is not a function
,$ http()错误:TypeError: object is not a function
代码中出现此特定错误,以动态加载导航选项卡.
CoffeeScript中的代码:
p4pControllers.controller 'navCtrl', [
'$routeParams'
'$scope'
'$http'
($http,$scope,$routeParams) ->
$http(
method:'GET'
url:'http://p4p-api.snyx.nl/tables'
).success (data) ->
$scope.tabs = data
return
return
$http.get('http://p4p-api.snyx.nl/tables').success (data) ->
$scope.tabs = data
return
return
]
Run Code Online (Sandbox Code Playgroud)
有谁看到我在这里做错了什么?
使用数组表示法注入依赖项时,参数的顺序很重要:
在你的代码中:
['$routeParams',
'$scope',
'$http',
function ($http, $scope, $routeParams) {
// $http argument ==> $routeParams
// $scope argument ==> $scope (by coincidence)
// $routeParams argument ==> $http
}
Run Code Online (Sandbox Code Playgroud)
所以,基本上,你正在做$routeParams.get()
,但$routeParams
没有方法get()
(也不是一个功能本身).
归档时间: |
|
查看次数: |
12284 次 |
最近记录: |