1
I’m an angled beginner. My routes don’t load in ng-view. When I click on the link my url looks like this
http://localhost:56845/Index.html#Add and nothing happens.
No error is displayed on console.
I use angle 1.6.
test js.
var MyApp = angular.module("MyApp", ['ngRoute']);
MyApp.config(function ($routeProvider, $locationProvider) {
$locationProvider.hashPrefix('');
$routePriveder.
when('/add', {
templateUrl: 'Paginas/add.html',
controller: 'AddController'
}).
when('/edit', {
templateUrl: 'paginas/edit.html',
controller: 'EditController'
}).
when('/delete', {
templateUrl: 'paginas/delete.html',
controller: 'DeleteController'
}).
when('/home', {
templateUrl: 'paginas/home.html',
controller: 'HomeController'
}).
otherwise({
redirectTo: '/home'
});
});
js controllers.
MyApp.controller("AddController", function ($scope) {
$scope.msg= "Add";
});
MyApp.controller("EditController", function ($scope) {
$scope.msg = "Editar";
});
MyApp.controller("DeleteController", function ($scope) {
$scope.msg= "deletar";
});
Index.html
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<title></title>
<meta charset="utf-8" />
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script src="Scripts/jquery-1.10.2.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-route.js"></script>
<script src="test.js"></script>
<script src="controllers.js"></script>
</head>
<body>
<nav role="navigation" class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#"> O que Tem Pra Hj? </a>
</div>
<ul class="nav navbar-nav">
<li><a href="#home">Home</a></li>
<li><a href="#add">Add</a><li>
<li><a href="#edit">Edit</a></li>
<li><a href="#delete">Delete</a></li>
</ul>
</div>
</nav>
<div ng-view> </div>
</body>
</html>
add.html
<h2 ng-controller="AddController">{{msg}}</h2>
now could not locate and my url was as follows http://localhost:56845/#Add
– Core
You changed the routes to minuscule ? If yes missed also change in href="#add"
– Maurício Júnior
Yes, I edited the question for everything too.
– Core
Remove the
$locationProvider
and$locationProvider.hashPrefix('')
I edited my answer to better view.– Maurício Júnior
same previous error, could not locate.
– Core
You are accessing /index.html try to access only http://localhost:56845
– Maurício Júnior
Also check that your templates page is correct, Pages and not pages
– Maurício Júnior
I changed to pages and when trying to access localhost:56845 error: Server Error in Application '/'.
– Core
How are you running the application ? It should be working, see this simple example of w3c, here they didn’t even need to add base url. https://www.w3schools.com/angular/angular_routing.asp
– Maurício Júnior
I did it by visual studio, I run using IIS.
– Core