如何在Angular JS中删除QueryString

时间:2016-09-28 05:20:10

标签: javascript angularjs

我有一个网址http://sitename.com/#/products/manage-options/31?form_id=32&type=create-template

在我的网址上方,我想删除type,但在我的代码下方无法正常工作。请检查

我的当前页面网址 - http://sitename.com/#/products/manage-options/31?type=create-template

<a href="" ng-click="clickMe();">Click Here</a>

$scope.clickMe = function(){
  $location.search('type', null);
  $state.go('products.manage_options', ({form_id: $stateParams.form_id}));
};

页面重定向后,我看到type未删除QueryString。

我的输出是 - http://sitename.com/#/products/manage-options/31?form_id=32&type=create-template我想要http://sitename.com/#/products/manage-options/31?form_id=32

请帮帮我。

编辑:

路由器

.state('products.manage_options', {
        url: '/manage-options/:product_id?form_id=&type',
        templateUrl: "views/product/manage_options.html",
        controller: "manageAttributeCtrl",
        data: {pageTitle: 'Manage Options'},
})

2 个答案:

答案 0 :(得分:4)

删除

//This will return you headers and text below of corrousponding header

    private List<Tuple<string, string>> GetPlainTextByHeaderFromWordDoc(string docname)
    {
        #region for Plain text collection from document
        List<Tuple<string, string>> docPlainTextWithHeaderList = new List<Tuple<string, string>>();

        string headerText = string.Empty;
        string finalTextBelowHeader = string.Empty;

        try
        {
            Document doc = ReadMsWord(docname, objCommonVariables);

            if (doc.Paragraphs.Count > 0)
            {
                //heading with 1st paragraph
                foreach (Paragraph paragraph in doc.Paragraphs)
                {
                    Style style = paragraph.get_Style() as Style;
                    headerText = string.Empty;
                    finalTextBelowHeader = string.Empty;

                    if (style.NameLocal == "Heading 1")
                    {
                    headerText = paragraph.Range.Text.TrimStart().TrimEnd();

                        //reading 1st paragraph of each section
                        for (int i = 0; i < doc.Paragraphs.Count; i++)
                        {
                            if (paragraph.Next(i) != null)
                            {
                                Style yle = paragraph.Next(i).get_Style() as Style;
                                if (yle.NameLocal != "Heading 1")
                                {
                                    finalTextBelowHeader += paragraph.Next(i).Range.Text.ToString();
                                }
                                else if (yle.NameLocal == "Heading 1" && !headerText.Contains(paragraph.Next(i).Range.Text.ToString()))
                                {
                                    break;
                                }
                            }
                        }

                        string header = Regex.Replace(headerText, "[^a-zA-Z\\s]", string.Empty).TrimStart().TrimEnd();
                        string belowText = Regex.Replace(finalTextBelowHeader, @"\s+", String.Empty);
                        belowText = belowText.Trim().Replace("\a", string.Empty);

                        docPlainTextWithHeaderList.Add(new Tuple<string, string>(header, belowText));

                    }
                }
            }
            else
            {
             //error msg: unable to read
            }

            doc.Close(Type.Missing, Type.Missing, Type.Missing);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.StackTrace);
        }
 }

  //This will read and return word document
  private Document ReadMsWord(string docName)
     {
    Document docs = new Document();
    try
    {
        // variable to store file path
        string FilePath = @"C:\Kaustubh_Tupe\WordRepository/docName.docx";
        // create word application
        Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
        // create object of missing value
        object miss = System.Reflection.Missing.Value;
        // create object of selected file path
        object path = FilePath;
        // set file path mode
        object readOnly = false;
        // open Destination                
        docs = word.Documents.Open(ref path, ref miss, ref readOnly,
            ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss,
            ref miss, ref miss, ref miss, ref miss, ref miss);

        //select whole data from active window Destination
        docs.ActiveWindow.Selection.WholeStory();
        // handover the data to cllipboard
        docs.ActiveWindow.Selection.Copy();
        // clipboard create reference of idataobject interface which transfer the data
    }

    catch (Exception ex)
    {
        //MessageBox.Show(ex.ToString());
    }
    return docs;
}

更改以下行:

$location.search('type', null);

答案 1 :(得分:1)

请参阅文档https://docs.angularjs.org/api/ng/service/ $ location #search

     $state.go('products.manage_options', ({form_id: $stateParams.form_id, type:null}));