用户在AngularJs中更新控制器时如何刷新$ state?

时间:2016-04-13 15:12:35

标签: javascript angularjs

我正在使用Angular UI路由器,并希望重新加载当前状态并刷新所有数据/重新运行控制器以获取当前状态。

如何使用$state.reload()$stateParams使用新数据重新加载状态?

app.js

.state('app.editControl', {
            url: '/edit/control',
            params: { controlId: null,processId: null, from: null, controlInProcessKey:null, refresh:null},
            templateUrl: 'views/control/createNewControl.html',
            controller: 'CreateControlCtrl',
            data: {
                authenticate: true
            },

ctrl.js

$scope.updateCallBack = function() {
    setInterval(function() {
        $scope.statusInfo = '';
    }, 1000);
    if ($scope.editControlToRisk) {
        console.log('EDITCONTROL');
        if ($scope.controlDTO.controlInProcessDTO.processKey) {
            $state.go('app.alignCtrlToProcess', {
                controlId: $scope.controlDTO.controlKey,
                controlInProcessKey: $scope.controlDTO.controlInProcessDTO.controlInProcessKey,
                processId: $scope.controlDTO.controlInProcessDTO.processKey
            });
        } else {
            $state.go('app.home');
        }
    } else {
        console.log('EDIT');
        $state.go($state.current, {
            controlId: $stateParams.controlId
        }, {
            reload: true
        });
        $scope.selectedAlignProcesses = new Date().getTime();
    }
};

1 个答案:

答案 0 :(得分:1)

你可以尝试

$state.go($state.current, $stateParams, {reload: true});// can check with inherit {reload: true, inherit: false}

您应该在$scope.selectedAlignProcesses = new Date().getTime();

之前使用$state.go