使用ui路由器重定向angularjs中的页面时如何传递参数?

使用ui路由器重定向angularjs中的页面时如何传递参数?,第1张

使用ui路由器重定向angularjs中的页面时如何传递参数

首先,您必须在route中添加参数。

app.config(function($stateProvider) {        $stateProvider        .state('first', { url: '/first', templateUrl: 'first.html'        })        .state('second', { url: '/second/:id', templateUrl: 'second.html'        })});

现在添加第一个控制器

app.controller.('firstCtrl' ,["$scope", "$state", function($scope, $state){    $scope.userInput <- come from user    $scope.clickThis=function() {        $state.go("second", { id: $scope.userInput });    }}]);

在第二个控制器中注入$ stateParams

//my second.htmlapp.controller.('secondCtrl',["$scope", "$state", "$stateParams", function($scope, $state, $stateParams){    $scope.id = $stateParams.id;})


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5020039.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存