$ uibModalInstance的角度注入器错误

时间:2016-02-05 12:39:16

标签: javascript angularjs

我正在尝试通过$ uibModalInstance对表单实现取消功能。当我点击“添加新员工”按钮时,表单工作正常,但是当我尝试更新它时(现在使用id的hardoceded值)我得到了错误:

 [$injector:unpr] http://errors.angularjs.org/1.4.8/$injector/unpr?p0=%24uibModalInstanceProvider%20%3C-%20%24uibModalInstance%20%3C-%20efController

为什么我不能将uibModalInstance注入此控制器的任何想法?为什么只有这个动作呢?这是我的控制者:

angularFormsApp.controller('efController',
function efController($scope, $window, $routeParams,$uibModalInstance, DataService) {
    if ($routeParams.id) {
        $scope.employee = DataService.getEmployee($routeParams.id);
    } else {
         $scope.employee = { id: 0 };
    };


    $scope.editableEmployee = angular.copy($scope.employee);
    $scope.departments = [
         "Engineeting",
                "Marketing",
                 "Finance",
                "Administration"
    ];
    $scope.submitForm = function () {
        if ($scope.editableEmployee.id == 0) {
            //insert new employee
            DataService.insertEmployee($scope.editableEmployee);
        } else {
            //update
            DataService.updateEmployee($scope.editableEmployee);
        }


        $scope.employee = angular.copy($scope.editableEmployee);
            $uibModalInstance.close();
    }
    $scope.cancelForm = function () {
         $uibModalInstance.dismiss();
    }

});

我的主应用程序脚本:

var angularFormsApp = angular.module('angularFormsApp',     ['ngRoute','ui.bootstrap']);
angularFormsApp.config(function($routeProvider) {
    $routeProvider
        .when("/home", {
            templateUrl: "app/Home.html",
            controller: "HomeController"
        }).when("/newEmployeeForm", {
            templateUrl: "app/EmployeeForm/efTemplate.html",
            controller: "efController"
        }).when("/updateEmployeeForm/:id", {
            templateUrl: "app/EmployeeForm/efTemplate.html",
            controller: "efController"
        }).otherwise({
                redirectTo:"/home"
        });
});   

 angularFormsApp.controller("HomeController",
function ($scope, $location, $uibModal, DataService) {
    $scope.showCreateEmployeeForm = function () {
         // $location.path('/newEmployeeForm');
          $uibModal.open(
        {
            templateUrl: 'app/EmployeeForm/efTemplate.html',
            controller: 'efController'
        });
    };
    $scope.showUpdateEmployeeForm = function (id) {
        $location.path('/updateEmployeeForm/'+id);
    };
});

0 个答案:

没有答案