1

I have an angular app in which i have the following:

    <div class="col-md-5 form-inline">
        <label for="bdate">Beginning Date:</label>
        <input type="date" class="form-control" ng-model="begindate" id="bdate" placeholder="mm-dd-yyyy">
    </div>
    <div class="col-md-4 form-inline">
        <label for="edate">End Date:</label>
        <input type="date" class="form-control" ng-model="enddate" id="edate" placeholder="mm-dd-yyyy">
    </div>
    <div class="col-md-3">
        <a href="report/{{begindate}}/{{enddate}}" class="btn btn-default pull-right" role="button">Export</a>
    </div>

When i click on the export button, the url that should be generated is not right.

http://localhost:8000/myapp/report/"2015-05-01T05:00:00.000Z"/"2015-05-26T05:00:00.000Z"

But it should be generated without the quotes. What is going wrong here?

1 Answer 1

4

You need to use toISOString() method

<div class="col-md-3">
    <a href="report/{{begindate.toISOString()}}/{{enddate.toISOString()}}" class="btn btn-default pull-right" role="button">Export</a>
</div>

You can check it using the following plunker http://plnkr.co/edit/9HKmXBCh7Xn1QGEap3gC?p=preview

Sign up to request clarification or add additional context in comments.

3 Comments

Your plunker seems to just be a "Hello World" plunker, where is the code related to this problem?
@SunilD. check it again now. It contains two URLs one of them use toISOString and other don't
Yup, thanks for doing that! I don't know why, but I'm really curious as to why this happens? I guess the answer is in the source code :) ... Also, if the OP is reading this you might want to use ng-href when you create dynamic URLs like this...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.