Reinitialize an Angular.js controller

后端 未结 2 1444
天涯浪人
天涯浪人 2020-12-16 12:14

if you have a controller to manipulate $scope variables in Angular.js, is there an idiomatic way to:

  • reset the controller\'s $scope, and
  • restart contr
2条回答
  •  青春惊慌失措
    2020-12-16 13:02

    If you are using angular-ui-router then you should do it in this way:

    myapp.Controller('SampleController', function($state) {
    
        $scope.navigate = function (stateName) {
            if ($state.is(stateName)) {
                $state.reload();
            } else {
                $state.go(stateName);
            }
        }
    });
    

提交回复
热议问题