我是AngularJS的新手,目前我得到了一个"TypeError:$route.current is undefined“的提示。请参考下面的代码:
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>
下面是当用户单击"Topic details“时将显示angularParam.html的angularParam.html
<!-- angularParam.html -->
<h2>Angular</h2>
<div>{{ text }}</div>
<div>{{ tutorialid }}</div>
我想要实现的是访问路径的属性,即在我的angularParam.html中显示"This is angular“文本
有人能帮我这个忙吗?提前谢谢。
发布于 2018-06-04 05:23:04
所以有两件事:
$route
。因此可以从此处删除ng-controller
。$route.current.$$route.mytext
访问mytext
。查看我创建的plnk:https://plnkr.co/edit/2jmErSMSSK7lA9cZPQ3m?p=preview
https://stackoverflow.com/questions/50664209
复制相似问题