如何在刷新页面后或在URL中更改值后设置保持检查单选按钮

时间:2017-05-09 07:17:56

标签: javascript jquery angularjs

您好我想在刷新页面后使用之前的值检查我的单选按钮我还在控制器中设置了变量值,但它无法正常工作。这里我的html和角度代码

<script>app.controller('commonController', ['$scope', 'httpMethodService', '$rootScope', 'growl', 'helperService', 'userService', '$auth','$routeParams',
function ($scope, httpMethodService, $rootScope, growl, helperService, userService, $auth,$routeParams,$routeProvider) {

 $scope.$on('$routeChangeSuccess', function() {
     if($routeParams.result == 'mlb'){

         $scope.result == '1';
     }else{

         $scope.result == '2';
     }
        // $routeParams should be populated here
      });


    helperService.checkSubscribed();
    $rootScope.isLoggedIn = false;
    if (userService.checkExistKey('u_id')) {
        $rootScope.isLoggedIn = true;
    } else {
        console.log("not-login");
        $rootScope.isLoggedIn = false;
    }
    $scope.$watch('isLoggedIn', function () {
        helperService.checkSubscribed();
    });

    $scope.authenticate = function (provider) {
        $auth.authenticate(provider);
    };
}]);</script>

这是我的HMTL

    <div ng-init="submitResult(result);"  class = "headerradio">

                        <lable>Choose a game- :</lable>
                        <input type="radio" ng-model='result'ng-click="submitResult(result);clearSearchParam();"  ng-value='"1"' name="rdoResult">MLB
                        <input type="radio" ng-model='result' ng-click="submitResult(result);clearSearchParam();" ng-value='"2"' name="rdoResult">NFL

  </div>

第一个控制器将加载,所以我使用$ routParams设置值并设置结果值。但是这段代码不起作用。

0 个答案:

没有答案