AngularJS Uncaught ReferenceError:未定义控制器

时间:2017-11-08 13:01:02

标签: javascript c# html angularjs

我正在尝试使用Web Api准备在基础上记录数据所需的基础设施......我的问题是为什么会出现此错误:

  

ReferenceError:未定义WebApi
      在Scope。$ scope.salvar(Controller.js:22)
      at fn(eval at compile(angular.js:15500),:4:138)
      在回调(angular.js:27285)
      在范围。$ eval(angular.js:18372)
      在Scope。$ apply(angular.js:18472)
      在HTMLButtonElement。 (angular.js:27290)
      在HTMLButtonElement.dispatch(jquery-3.2.1.js:5206)
      在HTMLButtonElement.elemData.handle(jquery-3.2.1.js:5014)

我的代码是:

Controller.js

prontuariogestanteapp.controller("ProntuariogCtrl", ["$scope", "CalculadorIMC", "WebApi", function ($scope, calculadorIMC, WebApi) 
{
    $scope.tabs = [
        { Title: "Dados Básicos", PageToDisplay: "./Html/Dados_Basicos.html" },
        { Title: "1º Mês", PageToDisplay: "./Html/Mes_1.html" },
        { Title: "2º Mês", PageToDisplay: "./Html/Mes_2.html" },
        { Title: "3º Mês", PageToDisplay: "./Html/Mes_3.html" },
        { Title: "4º Mês", PageToDisplay: "./Html/Mes_4.html" },
        { Title: "5º Mês", PageToDisplay: "./Html/Mes_5.html" },
        { Title: "6º Mês", PageToDisplay: "./Html/Mes_6.html" },
        { Title: "7º Mês", PageToDisplay: "./Html/Mes_7.html" },
        { Title: "8º Mês", PageToDisplay: "./Html/Mes_8.html" },
        { Title: "9º Mês", PageToDisplay: "./Html/Mes_9.html" },
        { Title: "Pós-Parto", PageToDisplay: "./Html/Mes10_Pos_Parto.html" }
    ];

    $scope.salvar = function()
    {
        WebApi.salvar($scope.Mes1);
    };
}

2 个答案:

答案 0 :(得分:2)

更改

$scope.salvar = function WebApi()
{
    WebApi.salvar($scope.Mes1);

};

$scope.salvar = function()
{
    WebApi.salvar($scope.Mes1);

};

您不能将方法命名两次($ scope.salvar和WebApi)。

答案 1 :(得分:0)

解决@Jasper Seinhorst建议后,您必须检查以下内容:

  1. js 文件,其中 index.html
  2. 中正确包含了WebApi服务
  3. 您的 WebApi 服务存储在模块中;确保模块是您要使用它的模块的依赖