I'm working with AngularJS 1.8 and I'm not able to make a proper redirection between pages.
I need to make a redirection to /post/:id from home page (/).
Rather than making the redirection it gets stuck in the next url: {{project_name}}/#!/#%2Fpost%2F1
This is my code:
// Template home.html
<lx-tab lx-label="Post">
<div class="p+">
<div class="card top-space" ng-repeat="post in posts">
<div class="p+">
<strong class="fs-headline display-block tc-red-900">
{{post.title}}
</strong>
<div class="paragraph fs-body-1 mt+">
{{post.body}}
</div>
<div class="card__actions">
**<a href="#/post/{{post.id}}" class="btn btn--m btn--blue btn--flat" lx-ripple>Leer mas</a>**
</div>
</div>
</div>
</div>
</lx-tab>
// template post.html
<div class="card top-space">
<div class="p+">
<strong class="fs-headline display-block tc-red-900">
{{post.title}}
</strong>
<div class="paragraph fs-body-1 mt+">
{{post.body}}
</div>
</div>
</div>
// Controller
const app = angular.module("FinalApp");
app.controller("MainController", function($scope, $resource){
Post = $resource('https://jsonplaceholder.typicode.com/posts/:id', {id: '@id'});
User = $resource('https://jsonplaceholder.typicode.com/users/:id', {id: '@id'});
$scope.posts = Post.query();
$scope.users = User.query();
})
app.controller("PostController", function($scope, $resource, $routeParams){
Post = $resource('https://jsonplaceholder.typicode.com/posts/:id', {id: '@id'});
$scope.post = Post.get({id: $routeParams.id});
})
// main script with Router
angular.module("FinalApp",["lumx","ngRoute", "ngResource"])
.config(function($routeProvider){
$routeProvider.when("/",{
controller: "MainController",
templateUrl: "src/templates/home.html"
});
$routeProvider.when("/post/:id", {
controller: "PostController",
templateUrl: "src/templates/post.html"
});
});
Any idea?
Thanks!
question from:
https://stackoverflow.com/questions/65888165/angularjs-stuck-with-routeprovider 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…