AngularJS issues with view routing

0

I'm developing a web application with AngularJS 1.6, and I'm encountering an error only when I open index.html right from the page. However, when running directly from the IDE it works normally. Here is the error print:

Index.htmlcode:

<bodyng-app="codeAmApp">

<div ng-controller="myCtrl" class="container">
    <div class="btn-group btn-block">
        <a class="btn btn-success pull-right" href="#!categoria"> + Categoria </a>
        <a class="btn btn-success pull-right" href="#!tarefa"> + Tarefa </a></button>
        <a ng-click="mostrar = !mostrar" ng-show="mostrar" class="btn btn-success pull-right" href="#!listaPorCategoria"> Lista de tarefas por categoria </a></button>
        <a ng-click="mostrar = !mostrar" ng-hide="mostrar" class="btn btn-success pull-right" href="#/!"> Lista de tarefas </a></button>
    </div>
    <div ng-view></div>
</div>
</body>

Angular Code JS:

var codeAmApp = angular.module('codeAmApp', ["ngRoute"]);

codeAmApp.config(function($routeProvider) {
    $routeProvider
        .when("/", {
            templateUrl : "porTarefa.html"
        })
        .when("/categoria", {
            templateUrl : "categoria.html"
        })
        .when("/tarefa", {
            templateUrl : "tarefa.html"
        })
        .when("/listaPorCategoria", {
            templateUrl : "porCategoria.html"
        })
        .otherwise({
           redirectTo: '/'
        });
});
    
asked by anonymous 13.08.2017 / 23:40

1 answer

0

This is simply due to the fact that you are opening the file directly.

I tried to run JQuery by opening the HTML file directly in Chrome and gave the same error. I do not remember the version of Google Chrome nor from JQuery), like Apache or IIS.

Some IDEs have a built-in Web server, as is the case with Brackets, which I use in Ubuntu 16.04, and certainly should be the case with your IDE.

To resolve this problem you will have to configure your Web server and access from localhost.

    
14.08.2017 / 03:30