【发布时间】:2016-05-22 23:03:18
【问题描述】:
我知道这可能很简单,但我收到了这个错误
无法获取未定义或空引用的属性“get”
当我从控制器调用我的 api 时
rmdsController.$inject = ['$scope', 'rmds'];
function rmdsController($scope, rmds, $http) {
$scope.Calculate = function () {
alert('made it');
$("#spinner").show();
$http.get('/api/rmd/calcRMDdist/')
.success(function (data) {
// Do stuff with data.
})
.catch(function (err) {
// Log error somehow.
})
.finally(function () {
// Hide loading spinner whether our call succeeded or failed.
$scope.loading = false;
});
}
【问题讨论】:
-
您尚未将
$http注入控制器。$inect语句中缺少它。另外,不要使用.success,它已被弃用;请改用.then。
标签: angularjs asp.net-mvc angular-controller