2016-06-15 6 views
0

Я новичок в angularjs. Я пытаюсь сохранить значение в cookieStore, но я становлюсь ниже ошибки.angularjs-1.2.14.js: 9509 ТипError: Не удается прочитать свойство 'put' of undefined

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 не умеет читать.

Где я совершил ошибку? В моем коде есть много функций, и я вставил только одну функцию, где я получаю ошибку.

+0

Где и как вы называете 'ivm.visualElements.Bars'? – Dieterg

ответ

0

Вы должны добавить $inject свойство к контроллеру, а также, как вы делали с run блока

ivm.visualElements.Bars.$inject 
= ['chartController', 'barController', '$timeout', '$cookieStore', '$rootScope'];