如何将参数添加到Angularjs中的当前URL

时间:2017-01-25 11:35:52

标签: javascript angularjs location

我用这个

获得了我当前的网址
   $location.url() which it '/details

这次我想添加一些参数,如

'/details/student' 

我如何添加' /学生'点击我当前的网址,任何人都可以提供帮助。谢谢。

  <tabset>
<tab heading="student" ng-click = "changeRoutes('student')">
    <h4>STUDENTS</h4>
    <p>Best students..</p>
</tab>
<tab heading="teacher" ng-click = "changeRoutes('teacher')">
    <h4>TEACHERS</h4>
    <p>Best teachers..</p>
</tab>

1 个答案:

答案 0 :(得分:1)

您需要为此定义路由器,如下所示: -

$stateProvider
//considering route.state is your current state and you need to go on student
  .state(route.state + '.student', {
    url: '/student',
    templateUrl: 'app/examples/student/student.tmpl.html',
    controller: 'StudentController'
  });

然后在您的详细信息控制器中,您需要移动到学生,如下所示

$scope.baseState.name = $state.current;
$state.go($scope.baseState.name + '.student');

通过这种方式,您将在加载时为所有选项卡加载模板。