Angularjs problems with view routing

Asked

Viewed 55 times

0

I am developing a web application with Angularjs 1.6, and I am encountering an error only when I open index.html directly from the page. However, when running directly from the IDE it works normally. Follows print of error: inserir a descrição da imagem aqui

Code of index.html:

<body ng-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>

Code of the Angularjs:

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: '/'
        });
});

1 answer

0

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

Angularjs requires an HTTP server (in fact, Google technologies, including Chrome itself, require this. I tried running Jquery by opening the HTML file directly in Chrome and gave the same error. I can’t remember the version of Google Chrome or Jquery), such as Apache or IIS.

Some Ides have a built-in web server (built-in), as is the case with Brackets, which I use in Ubuntu 16.04, and certainly the case with your IDE.

To resolve this issue you will need to configure your web server and access from localhost.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.