【问题标题】:I have a problem with my js file using AngularJS: "Uncaught Error: [$injector:modulerr]"我使用 AngularJS 的 js 文件有问题:“未捕获的错误:[$injector:modulerr]”
【发布时间】:2019-04-04 13:49:36
【问题描述】:

我正在构建 AngularJS,这个家伙使用的版本是 1.0.8,我使用的是 1.7.8 angular 并且想要更新它。有人可以帮我吗?

文件:index.html

<!doctype html>
<html ng-app="pessoas">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Pessoas</title>
</head>

<body>

<div ng-controller="CtrlPessoas">
    <h1>Sistemas de gerenciamento de pessoas</h1>

    <ng-view></ng-view>

</div>

</body>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>
<script src="pessoas.js"></script>

</html>

文件:listar.html

<h2>Listagem de Pessoas</h2>

<ul>
    <li ng-repeat="pessoa in pessoas">
        {{pessoa.nome}}, {{pessoa.cidade}}
    </li>
</ul>

文件:pessoas.js

angular
    .module('pessoas', [])

    .config(function ($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: 'listar.html'
        });
    })

    .controller('CtrlPessoas', function ($scope) {
        $scope.pessoas = [
            {nome: "Maria", cidade: "São Paulo"},
            {nome: "Jose", cidade: " Cacem"},
            {nome: "Dave", cidade: "Sintra"},
            {nome: "Juan", cidade: "Mexico"}
        ];
    });

【问题讨论】:

    标签: javascript jquery html angularjs


    【解决方案1】:

    您缺少 ngRoute 模块:

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular-route.min.js"></script>  
    
    
    angular.module('pessoas', ['ngRoute'])
    

    【讨论】:

    • 你能告诉我哪里不见了吗?
    • @Dacriber 在 angular.min.js 脚本下面添加脚本,然后像我发布的那样将ngRoute 添加到angular.module
    • 非常感谢
    猜你喜欢
    • 1970-01-01
    • 2017-01-29
    • 2016-05-09
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    相关资源
    最近更新 更多