2016-06-15 95 views
0

我是angularjs的新手。我試圖在cookieStore中存儲一個值,但是出現錯誤。angularjs-1.2.14.js:9509 TypeError:無法讀取undefined的屬性'put'

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']; 
相關問題