Answer the question
In order to leave comments, you need to log in
What's wrong with routing?
Hello, tell me what I'm doing wrong.
Config for routes
app.config(function($routeProvider){
$routeProvider
.when('/',{
templateUrl: 'template/main.html'
})
.when('/phones/:phoneId',{
templateUrl: '/template/phone.html',
controller: 'PhoneCntrl'
})
.otherwise({redirectTo:'/'})
app.controller('PhoneCntrl','$routeParams', function($scope, $routeParams){
$scope.phoneId = $routeParams.phoneId;
});
<button><a href="/#/template/{{phone.id}}">Посмотреть</a></button>
Answer the question
In order to leave comments, you need to log in
Use ng-href instead of href - this thing takes into account the peculiarities of how Angular works, for example, asynchronously loading values into a list of elements. Otherwise, everything seems to be correct, except that in the controller you use one variable, and in the template you display the value of another:
$scope.phoneId = $routeParams.phoneId;
// Лучше - $scope.routeParams = $routeParams;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question