访问角度cookie在视图中

时间:2014-07-05 13:38:31

标签: angularjs cookies angularjs-scope

我用一些像

这样的对象填充我的angularjs cookie
 $scope.benchmarks = function(product) {               
     $cookieStore.put("benchmark_prods", product);
     $scope.benchmarks = $cookieStore.get("benchmark_prods");
     console.log(benchmarks); //is getting filled
 };
如果cookie包含元素但我不知道如何

,那么我希望在视图中访问

我试过

 <div ng-repeat="product in products">
//here the click event which is stroing product in cookie an simultanly shuld update cookie loop
   <a data-placement="bottom" ng-click='benchmarks(product)' title="" rel="tooltip" class="button-icon jarviswidget-delete-btn" href="javascript:void(0);" data-original-title="Delete"><i class="fa fa-bookmark"></i></a>
</div>

             <div ng-controller="MainCtrl">
                        <fieldset>
                            <section>
                                <div class="panel-heading">
                                    <legend class="params">
                                        <h4 class="panel-title">
                                            Benchmarks  
                                        </h4>                                            
                                    </legend>
                                </div>
                                <div ng-repeat="benchmark_prod in benchmarks">
                                    {{benchmark_prod}}

                                </div>
                                <div class="inline-group" id="conf_display">

                                </div>
                    </div>

但不起作用

1 个答案:

答案 0 :(得分:1)

         $scope.benchmarks = function(product)
         {               
            $cookieStore.put("benchmark_prods", product);

            if($cookieStore.get("benchmark_prods")!=null &&  $cookieStore.get("benchmark_prods")!="")
            {
               $scope.benchmarkspro=$cookieStore.get("benchmark_prods")
            }

            console.log(benchmarkspro); //is getting filled
         };

在html中将基准测试更改为benchmarksp。