角度注入器错误未知提供商

时间:2016-02-23 10:41:38

标签: angularjs dependency-injection

请帮助我,

我有一个像这样的控制器:

下面的showAlert是通过ng-click = showAlert(data.nip)按钮触发的

var showAlert = function ($scope, $modal, $log, nip) {
    var modalInstance = $modal.open({
        templateUrl: 'public/js/modal.html',
        controller: ModalInstanceCtrl,
        resolve: {
            nip: function () {
                return nip;
            }
        }
    });
}
showAlert.$inject = ['$scope', '$modal', '$log', 'nip'];

var ModalInstanceCtrl = function ($scope, $modalInstance, nip) {
    $scope.nip = nip;
    console.log("Nilai NIP : "+nip)
};

来自州:

.state('masterpegawai.alltalenta.modal', {
        url: '/modal',
        views:{
          "modal": {
            controller: showAlert,
          }
        }
     })

它会抛出这样的错误:

Error: [$injector:unpr] Unknown provider: nipProvider <- nip

1 个答案:

答案 0 :(得分:-1)

您正在尝试注入nip,但是从您的代码中,您尝试将其作为参数传递:

showAlert.$inject = ['$scope', '$modal', '$log', 'nip']; <-- You can't inject  'nip'