I am new to AngularJS and currently I am getting an "TypeError: $route.current is undefined". Please see code below:
var sampleApp = angular.module('sampleApp', ['ngRoute']);
sampleApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/Angular/:topicId', {
mytext: 'This is angular',
controller: 'angularControllerParam',
templateUrl: 'angularParam.html'
});
}]);
sampleApp.controller('angularControllerParam', function($scope, $routeParams, $route) {
$scope.tutorialid = $routeParams.topicId;
$scope.text = $route.current.mytext;
});
<body ng-app="sampleApp">
<h1>Accessing parameters from the route</h1>
<table class="table table-stripped" ng-controller="angularControllerParam">
<thead>
<tr>
<th> # </th>
<th> Angular JS topic </th>
<th> Description </th>
</tr>
</thead>
<tbody>
<tr>
<td> 1 </td>
<td> 1 </td>
<td> Controllers </td>
<td> <a href="#!Angular/1"> Topic details </a> </td>
</tr>
<tr>
<td> 2 </td>
<td> 2 </td>
<td> Models </td>
<td> <a href="#!Angular/2"> Topic details </a> </td>
</tr>
<tr>
<td> 3 </td>
<td> 3 </td>
<td> Directives </td>
<td> <a href="#!Angular/3"> Topic details </a> </td>
</tr>
</tbody>
</table>
<div ng-view></div>
</body>
And below is the angularParam.html where when the user clicked "Topic details" it will show angularParam.html
<!-- angularParam.html -->
<h2>Angular</h2>
<div>{{ text }}</div>
<div>{{ tutorialid }}</div>
What I am trying to achieve is to access the properties of the route which is to show "This is angular" text in my angularParam.html
Can someone help me on this? Thanks in advance.
angular-routeversion are you using ?