1

I'm storing token and passing it to angular from index.cshtml as

<app data-serverData='@ViewData["token"]'>Loading..</app>

very thing working fine but in webtools

enter image description here

It appears very clearly.So I want to remove that by writing in a script

<script id=tempScript>
token = @ViewData["token"]
</script>

or

<div id=tempClass>
<input type="hidden" token="@ViewData["token"]">
</div>

Now,In any angular component after collecting the token I want to remove the script or Div like in Jquery $(#tempScript).remove(); or same for Div. How can I approach this in typescript.

k11k2
  • 2,036
  • 2
  • 22
  • 36

1 Answers1

1

You can still use jQuery in Angular. Just insert script tag links to jquery.js script anywhere in your index.html (or _Layout.cshtml if you used ASP.NET MVC) It's good to put before closing

<script src="./path/to/your/jquery.min.js"></script>

Then you can use jQuery in any component, just put this line before declare @Component.

declare var jQuery: any;

Then you can remove it by

jQuery('#tempscript').remove();
  • not working. any typescript related solution would be a better. – k11k2 Dec 13 '17 at 07:09
  • However Typescript will be compiled to Javascript at the end. When we put anything inside AppComponent selector will be overwritten. So please make sure you put your data outside AppComponent's selector. I put sample here: https://embed.plnkr.co/xVS5jJpOZn5ZxvR6XLXR/ – Weerayut Teja Dec 13 '17 at 08:38
  • 1
    https://stackoverflow.com/questions/37337185/passing-asp-net-server-parameters-to-angular-2-app/37384405#37384405 – Eliseo Dec 13 '17 at 08:43
  • @WeerayutTeja am using aspnetcore angular universe. jquery is not much recommend by the team. so in such of other ways. – k11k2 Dec 13 '17 at 10:57
  • @k11k2 Agreed jQuery is easiest way to do but jQuery or manipulate DOM directly isn't recommend for Angular Universal. For me I sent data from server to Angular via Json. Eliseo's link also useful. But have you send secret data to Angular right? But anyway if it's encoded enough I don't think it will be the problem if send via JSON. Might need to apply Cross-Origin Request on ASP.NET Core (https://learn.microsoft.com/en-us/aspnet/core/security/cors). Anyway It just my opinion your situation might difference. – Weerayut Teja Dec 13 '17 at 11:12
  • @WeerayutTeja what that system.import really defines in that above link ? – k11k2 Feb 22 '18 at 05:49