0
質問のタイトルがどれほど正しいかわからない 私は検索の入力を配列に格納し、その配列をクッキーに入れています。ページがリフレッシュされている間、私はinit関数を使用して、クッキーに格納されているものとng repeatで使用されるarrを初期化します。コンソールで、--->の行にエラーをページの読み込み時にクッキーから配列を取得できません
nameapp.controller('NameCtrl',
function($scope,$http,$window, $cookieStore,$sessionStorage,$cookies ,myService){
// code for storing array in the cookie
$http.get('https://finance.google.com/finance/info?client=w&q='+$scope.stock).success(function(data,status)
{
$scope.share=JSON.parse(data.substring(5,data.length-2));
$scope.arr.push($scope.share);----> error here
console.log(status+"-------"+JSON.stringify($scope.arr));
}).error(function()
{
alert("fail");
})
}
;
$scope.init = function() {
var s =$cookies.get("arr");
$scope.arr=$cookies.get("arr") ;
console.log("JSON.stringify($cookies.get('arr'))="+s);
}
}
);
</script>
</head>
<body ng-controller="NameCtrl" ng-init="init()">
<form ng-submit="finddet()">
<input type="text" ng-model="stock">
<input type="submit">
</form>
<ul>
<li ng-repeat="name in names">{{name}}</li>
<li ng-repeat="sr in arr track by $index"> value : {{sr.l_cur}} <a href='#' ng-click="removename(sr)"> remove </a></li>
</ul>
</body>
</html>
:ページ上のクッキーの1とNGの繰り返し配列を初期化する方法が
TypeError: $scope.arr.push is not a function
at (index):99
わからないが、私はエラーに直面しています負荷。いかなる訂正もお願いします。