2

I am trying to find out if there is a way to add a piece of Angular in a project built on different framework..

To be more specific, I have a .NET MVC project (Razor for the markup) from which I want to make some ajax calls and update bits of the UI. I rejected JQuery so far since I want to use a more modern approach(I am considering vanilla or vue because of the easy learning curve).

I thought the solution would be given by Angular Elements so I could have something like:

<my-popup message="Use Angular!"></my-popup>

but it doesn't seem to work like that.

Again, my point is to use Angular in a non-Angular project.

Any suggestion would be welcome.

Zze
  • 18,229
  • 13
  • 85
  • 118
George George
  • 571
  • 3
  • 7
  • 18
  • 1
    Are you using `angular` or `angularjs` ? You have tagged both and it can only be one. – Zze Nov 08 '18 at 21:17
  • I am considering Angular(2). Angularjs would be an option as well. Although, I am trying to plug Angular(2). But good point, my bad for putting both tags – George George Nov 08 '18 at 21:26
  • 1
    `Angular > Angularjs` in my opinion. You can even mod your T4 template to generate you `.ts` classes which is really handy. Can't do anything like that with `angularjs` – Zze Nov 08 '18 at 21:29
  • 1
    Due to the architecture of Angular being a SPA, if you want to use Razor you are out of luck. The entire front end is brought down in a bundle the first time you hit the server and then the only communication it has with the server beyond that is via ajax calls; Even navigation is trapped in the SPA without requiring the server to process the request. Apparently there is a [server side](https://angular.io/guide/universal) option for Angular, however i've personally not heard great reviews and have not used it myself. Hope this helps. – Zze Nov 08 '18 at 21:37
  • 1
    @Zze That's the case. It's the other way round - render an Angular 'portion' inside an existing razor view. Like what we can do with a simple But I now what you mean. Thank you for taking he time – George George Nov 08 '18 at 21:45

1 Answers1

2

Check this post on how to compile Angular Elements into a web component to use it.

Aleš Doganoc
  • 11,568
  • 24
  • 40