我是 angularjs 的新手。我正在尝试在 cookieStore 中存储一个值,但出现以下错误。
angularjs-1.2.14.js:9509 TypeError: Cannot read property 'put' of undefined
我的代码:
(function () {
'use strict';
var ivm = ivm || {};
angular
.module('ivm', ['ivml.chart', 'ngCookies'])
.run(run);
run.$inject = ['$rootScope', '$location', '$cookieStore', '$http'];
function run($rootScope, $location, $cookieStore, $http) {
// keep user logged in after page refresh
$rootScope.xaxis_length = $cookieStore.get('xaxis_length') || {};
}
var ivm = ivm || {};
ivm.visualElements = ivm.visualElements || {};
ivm.visualElements.Bars = function Bars(chartController, barController, $timeout, $cookieStore, $rootScope) {
var Bars = {
elements: {
chartController: chartController,
barController: barController,
$timeout: $timeout,
xscale: null,
yscale: null,
svg_g: null,
frame: null,
index: -1
},
attributes: {
fill: "black", //@i fill color of the bar
fillOpacity: 1, //@i fill opacity of bar
stroke: null, //@i color of the bar's outline
strokeWidth: 1, //@i stroke width of the bar's line
strokeOpacity: 1, //@i opacity of the bar's outline
thickness: 5 //@i the bar's thickness (size parallel to the dependent dimension)
},
accessors: {
data: [], //@ir javascript object to plot
positionFunction: null,//@ir accessor for the bar's position on the nominal axis
valueFunction: null //@ir accessor for the the bar's value (size and direction)
},
events: {
mouseOverE: null, //@e mouse over event
mouseOutE: null, //@e mouse out event
clickE: null //@e mouse click event
}
}
var xaxis_length = "0";
console.log(xaxis_length);
$cookieStore.put('xaxis_length',xaxis_length);
我在上面的行中收到错误,put
无法读取。
我在哪里做错了?我的代码中有很多函数,我只粘贴了一个出错的函数。