$ rootScope未在控制器中定义

时间:2017-05-17 07:02:18

标签: javascript html angularjs

以下是我对控制器的定义。当我运行应用程序时,我得到了

" $ 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>

1 个答案:

答案 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;
            };

        }
    ]);