简体   繁体   English

AngularJS未捕获ReferenceError:控制器未定义

[英]AngularJS Uncaught ReferenceError: controller is not defined

I'm trying to prepare the infrastructure needed to record the data in base using Web Api... And my question is why is getting this error: 我正在尝试准备使用Web Api在数据库中记录数据所需的基础结构。我的问题是为什么会出现此错误:

ReferenceError: WebApi is not defined ReferenceError:未定义WebApi
at Scope.$scope.salvar (Controller.js:22) 在Scope。$ scope.salvar(Controller.js:22)
at fn (eval at compile (angular.js:15500), :4:138) 在fn(在编译时评估(angular.js:15500),:4:138)
at callback (angular.js:27285) 在回调时(angular.js:27285)
at Scope.$eval (angular.js:18372) 在Scope。$ eval(angular.js:18372)
at Scope.$apply (angular.js:18472) 在Scope。$ apply(angular.js:18472)
at HTMLButtonElement. 在HTMLButtonElement。 (angular.js:27290) (angular.js:27290)
at HTMLButtonElement.dispatch (jquery-3.2.1.js:5206) 在HTMLButtonElement.dispatch(jquery-3.2.1.js:5206)
at HTMLButtonElement.elemData.handle (jquery-3.2.1.js:5014) 在HTMLButtonElement.elemData.handle(jquery-3.2.1.js:5014)

My code is: 我的代码是:

Controller.js 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);
    };
}

Change 更改

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

};

to

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

};

You can't name a method twice ($scope.salvar and WebApi). 您不能两次命名方法($ scope.salvar和WebApi)。

After you resolve @Jasper Seinhorst suggestion you must check the following: 解决@Jasper Seinhorst的建议后,必须检查以下内容:

  1. The js file where WebApi service is included properly in your index.html index.html中正确包含WebApi服务的js文件
  2. Your WebApi service is stored inside a module; 您的WebApi服务存储在模块内部; ensure that module is a dependency for the module where you want to use it 确保模块是您要使用模块的依赖项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM