1

我有以下内容:

angular.module("thingy", ["ngCookies"]).directive("welcome", function() {
    return {
        link: function($scope, el, attr, ctrl) {
                        (if $cookies.something) {
                            // conditional cookie logic
                        }
        },
        templateUrl: "assets/html/_welcome.html"
    };
})

如何从该链接功能中读取或写入 cookie?

4

1 回答 1

5

你需要注入它。请参阅文档。

angular.module("thingy", ["ngCookies"]).directive("welcome", ['$cookies', function($cookies) {
  return {
    link: function($scope, el, attr, ctrl) {
      if ($cookies.something) {
        // conditional cookie logic
      }
    },
    templateUrl: "assets/html/_welcome.html"
  };
}])
于 2013-05-30T20:47:58.663 回答