出于某种原因,我在使用 cookieStore
时遇到问题。我将其添加到我的应用程序中的routes.js中:
var myApp = angular.module('myApp', ['ngRoute', 'ui.bootstrap', 'ngCookies']);
然后尝试在我的 TabCtrl
中使用它,如下所示:
myApp.controller('TabsCtrl', ['$scope', function ($scope, $cookieStore) {
$cookieStore.put('tab', '#/dashboard/summary');
我得到“无法读取未定义的属性'put'”
最佳答案
您只是将 $scope
注入(inject) Controller ,但需要 $scope
和 $cookieStore
。将 $cookieStore
添加到您的依赖项中,并确保您有右括号(方括号和常规括号)。您可能已经有了这个,但您还没有发布所有代码!
所以改变:
myApp.controller('TabsCtrl', ['$scope', function ($scope, $cookieStore) {
到...
myApp.controller('TabsCtrl', ['$scope', '$cookieStore', function ($scope, $cookieStore) {
关于javascript - 使用cookieStore : Cannot read property "put" of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24152221/