错误:$ injector:unpr未知提供程序 - AngularJS

时间:2017-01-12 11:04:41

标签: angularjs

我见过很多像这样的问题,却找不到相关的答案。这是我的脚本文件

var myApp = angular.module("myModule", []).controller("myController",function ($scope) {
      var employee = {
      firstname: "mak",
      lastname: "d",
      gender: "male"
    };
    $scope.employee= employee;
});

我不确定为什么我会收到此错误。我在浏览器上看到以下文字

{{   `employee.firstname`   }}
{{   `employee.lastname`    }}
{{   `employee.gender`   }}

3 个答案:

答案 0 :(得分:0)

如果您尝试在app.js中重命名Script.js,该怎么办?

 var myApp = angular.module("myModule",[]);

    myApp.controller("myController", function ($scope) {

var employee = { firstname: "mak", lastname: "d", gender: "male" };

                        $scope.employee= employee;
        });

或:

 angular.module("myModule",[]);
    angular.module("myModule").controller("myController", function ($scope) {
 var employee = { firstname: "mak", lastname: "d", gender: "male" };

                            $scope.employee= employee;
            });

答案 1 :(得分:0)

  

此错误是由于$ injector无法解析所需的依赖项而导致的。要解决此问题,请确保依赖关系已定义并拼写正确

并确保在索引文件中包含控制器js文件。

答案 2 :(得分:0)

$injector 无法解析所需的依赖关系导致此错误。要解决此问题,请确保定义依赖关系并拼写正确。

工作演示:

var myApp = angular.module('myModule',[]);

myApp.controller('myController', function($scope) {
    var employee = {
        firstname: "mak",
        lastname: "d",
        gender: "male"
    };

    $scope.employee= employee;
});

<div ng-app="myModule" ng-controller="myController">
  {{  employee.firstname }} {{  employee.lastname }} {{  employee.gender }}
</div>