$ cookieStore:如何实现它,以及如何销毁它?

时间:2015-04-30 05:28:49

标签: angularjs cookies session-cookies

现在我正在使用ngCookies,我需要知道如何实现它以及如何在用户注销时销毁该数据

我设置此功能以检索数据

$scope.localStorageInfo = function() {
    $scope.userDisplayInfoName = $cookieStore.get('username');
    $scope.userDisplayInfoEmail = $cookieStore.get('email');
  };
$scope.localStorageInfo();

$scope.signIn = function () {
        $scope.userDisplayInfoName = $rootScope.name.displayName;
        $scope.userDisplayInfoEmail = $rootScope.name.email;
        $cookieStore.put('username', $rootScope.name.displayName);
        $cookieStore.put('email', $rootScope.name.email);
};
那么,这是正确的方法吗?以及如何在用户注销时销毁该数据,以及如何从localStorage中删除该数据?

2 个答案:

答案 0 :(得分:2)

 <asp:GridView ID="grvstdRes" runat="server" CssClass="table table-bordered table-hover" OnRowCommand="grvstdRes_RowCommand" AutoGenerateColumns="false">
                                                <Columns>
                                                    <asp:TemplateField HeaderText="Document">
                                                        <ItemTemplate>
                                                            <asp:LinkButton ID="lnkstdres" runat="server" Text='<%#Eval("Alias") %>' 

CommandArgument='<%#Eval("Idinstance") %>' CommandName="StudentResAliasName" ></asp:LinkButton>
                                                            </ItemTemplate>
                                                        </asp:TemplateField>
                                                    </Columns>
                                               </asp:GridView>

   protected void grvstdRes_RowCommand(object sender, GridViewCommandEventArgs e)
    { 
        if(e.CommandName=="StudentResAliasName")
        {  
            using(objResultUnitBLL=new UnitBLL())
            {
                using(objUnitDTO=new UnitDTO())
                {
                    objUnitDTO = objResultUnitBLL.GetStudentResourceFile(Convert.ToInt64(e.CommandArgument));
                     string fileName=objUnitDTO.FileName; //to get the full path from DB
                     string[] pathArr = fileName.Split('\\'); // To split the path 
                     fileName = pathArr.Last().ToString(); //To get the file name  with extension
                     Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('../Upload/Instance/" + fileName + "','_newtab');", true); //to display the file in new window.
                }
            }
        } 
    }

答案 1 :(得分:1)

是的,这是正确的方式。你可以使用remove方法破坏你的cookie:

$cookieStore.remove('username');