M
M
Max2015-09-23 21:40:31
Angular
Max, 2015-09-23 21:40:31

Why does Error: ng:areq Bad Argument(routing, controller not visible) occur?

Hello, here is the routing code

.when('/',{
templateUrl: 'template/main.html'
})
.when('/phones/:phoneId',{
templateUrl: 'template/phone.html',
controller: 'PhoneCntrl'
})
.otherwise({redirectTo:'/'})

Controller code
app.controller('PhoneCntrl','$routeParams', function($scope, $routeParams){
$http.get('phones/' + $routeParams.phoneId + '.json').success(function(data) {
$scope.phone = data;
});
$scope.phoneId = $routeParams.phoneId;
});

And the calling code
<a ng-href="#/phones/{{phone.id}}" class="btn btn-primary">Show</a>

Routing works, it opens pages with the desired IP, but does not want to display the content.
When withdrawing
<h1>Тест</h1>
{{phone.phoneId}}
Only the word "Test" is displayed, and the error in the console is Error: ng:areq
Bad Argument
Argument 'PhoneCntrl' is not

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2015-09-23
@AMar4enko

app.controller('PhoneCntrl', ['$scope', '$routeParams', function($scope, $routeParams){
  $http.get('phones/' + $routeParams.phoneId + '.json').success(function(data) {
    $scope.phone = data;
  });
  $scope.phoneId = $routeParams.phoneId;
}]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question