angular页面传值 传递单个值传递对象

    xiaoxiao2023-03-24  5

    router配置中标明参数的名字. 以ui-router为例

    $stateProvider.state('state1', { url: '/path/:id', // 这个地方用简单字符串 templateUrl: '/path/to.html', params: { obj: null // 这个地方就可以随便你用了. 因为这个参数没在state的url中体现出来 } }).

    使用$state进行页面切换

    $state.go('state1', { id: '22', obj: { key: 'value' } });

    在controller中使用$stateParams中获取参数

    console.log($stateParams.obj)

    当然传递这种在url中没有体现的参数, 会在后退等操作时, 参数不可用.

    https://segmentfault.com/q/1010000002784915

    转载请注明原文地址: https://ju.6miu.com/read-1201139.html
    最新回复(0)