I'm learning angular, I'm trying to use routes for the first time but something is wrong with it, this is not working:
This is my main view(UsingDirectivesWithDataBinding.cshtml):
@{
Layout = null;
}
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script type="text/javascript" src="~/Scripts/angular-route.js"></script>
<script type="text/javascript" src="~/Scripts/AngularFile.js"></script>
<title>
Using AngularJS Directives and Data Binding
</title>
</head>
<body>
<div data-ng-app="myApp" data-ng-controller="SimpleController">
<a href="#/view1"> View 1</a>
<a href="#/view2"> View 2</a>
<div data-ng-view=""></div>
</div>
</body>
</html>
As you can see I have two links that call this route : '#/view2' or this one: '#/view1' but it's taking me to the Index page of Home Controller instead of stay in the same page and show the Partial Views I want to display. This is the code I have in Home Controller:
public ActionResult UsingDirectivesWithDataBinding()
{
return View();
}
public PartialViewResult View1()
{
return PartialView();
}
public PartialViewResult View2()
{
return PartialView();
}
This is my Javascript file(AngularFile.js):
var app = angular.module("myApp", ["ngRoute"]);
app.controller("SimpleController", function ($scope) {
$scope.firstName = "John";
$scope.lastname = "Doe";
$scope.customers = [
{ name: "Dave Jones", city: "Phoenix" },
{ name: "Jamie Riley", city: "Atlanta" },
{ name: "Heedy Rowt", city: "Memphis" },
{ name: "Thomas Winter", city: "Seattle" }
];
});
app.config(function ($routeProvider) {
$routeProvider.when("/view1", {
templateUrl: "/Home/View1",
controller: "SimpleController"
})
.when("/view2", {
templateUrl: "/Home/View2",
controller: "SimpleController"
})
.otherwise({redirectTo : "/view1"})
})
Why is not working?