以下是我对控制器的定义。当我运行应用程序时,我得到了
" $ rootScope未定义"。
任何人都可以帮助我理解这里的错误。
var webadmin = angular.module('PcPortal')
.controller('environmentController',
[
'$scope', '$http', '$rootScope',
function ($scope, $http) {
$http.get('http://localhost:52240/api/PcpEnvironment/GetAllEnvironments')
.then(function (response) {
$scope.Environments = response.data;
});
$scope.findSelectedItem = function (index) {
var env = $scope.Environments[index];
$rootScope.selectedEnv = env;
};
}
]);
Html行调用函数...
<td><a ng-click="findSelectedItem($index)" href="#/UpdateEnvironment">Update</a></td>
答案 0 :(得分:0)
您正在注入$rootScope
,但将其实例创建为$http
尝试此操作并将$http
实例创建为$http
,将$rootScope
实例创建为$rootScope
var webadmin = angular.module('PcPortal')
.controller('environmentController',
[
'$scope', '$http', '$rootScope',
function ($scope, $http, $rootScope) {
$http.get('http://localhost:52240/api/PcpEnvironment/GetAllEnvironments')
.then(function (response) {
$scope.Environments = response.data;
});
$scope.findSelectedItem = function (index) {
var env = $scope.Environments[index];
$rootScope.selectedEnv = env;
};
}
]);