1

I'm starting to learn Angular 2 and I am quite lost in some subjects... like the server.

Following the instructions for a Quick Setup I installed Node and npm... when I run the project in Node everything goes perfect. The label <label> gets recognized and it gets the template for that label (in this case an html form).

But when I run the same project in MAMP, that label doesn't get recognized and comes out a 'Failed to load resource' error in the console for the template associated to that label.

So I guess Angular 2 is dependent on Node and that's a problem because I want to upload later the project and I think my hosting plan doesn't allow me to run Node...

I don't know if I'm prejudging, maybe anybody can help me clear this... Thanks.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Adri
  • 56
  • 1
  • 6
  • I've all my projects under Apache, so I don't think this is a problem. Besides that your title says XAMPP but your question says MAMP. – Eric Martinez Mar 04 '16 at 11:56
  • Whatever webserver you use is not important. IIS, Apache or simple Express server. Angular 2 doesn't depend on the server in any way. – dfsq Mar 04 '16 at 13:04
  • XAMPP no it a server https://en.wikipedia.org/wiki/XAMPP the server in this case is (A) Apache, You can find how to configure an Apache server, I think that solving, and clarifies doubts,I hope it will help. – Angel Angel Mar 04 '16 at 13:16
  • Ok perfectionist, so the question is not if XAMPP of MAMP are servers, I know they aren't. Maybe is better LAMP vs MEAN or Apache vs Node. But all of you say Angular 2 doesn't need Node and can run on Apache, which was my real question... and follows to the next one: how? In Angular you just added some scripts and CSS to your HTML and you got Angular running. But as I have seen, Angular2 doesn't work that way... maybe somebody can explain this to this ignorant without calling me ignorant, I know I am. – Adri Mar 06 '16 at 10:05

3 Answers3

2

Angular2 has niether any Relation nor any Dependency on node.js.

You can write Angular2 app just using Angular2 packages without using node or mamp or xampp and host that app.

If you have written any thing in Angular2 and node.js combination then you can host it on free services like Heroku for testing purpose.

Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57
  • Thanks for your answer. I was investigating those free host services, but I prefer a "normal one" (Apache, PHP)... I'm still lost, but all of you are saying I don't need Node, so I'll go back in my steps and investigate how I can do that. – Adri Mar 06 '16 at 10:18
  • Know about Angular2 [Start Here](https://angular.io/docs/js/latest/quickstart.html) create first app [Video Tutorial](https://www.youtube.com/watch?v=uD6Okha_Yj0&noredirect=1) [Text Tutorial](https://angular-tutorial.quora.com/10-minutes-making-a-simple-Angular-2-Todo-App-Part-1) – Zeeshan Hassan Memon Mar 06 '16 at 10:56
1

Final solution:

Ok, wrong again. I'm the worst detective ever.

  • it works with TypeScript as with JavaScript, just need the "npm start" to compile TypeScript into JavaScript. Then it automatically runs on a "localhost", but once compiled, you can run the index.html like any html, without the need of a server, like you were all saying, it's not like .php which makes all sense.

  • so the problem that led me to all of this misunderstandings was that the Node "localhost" worked and the Apache "localhost" didn't, and the mistake was that I was calling into @Component: templateUrl: "../template/file.html", and the path is written in "/app/whatever.js", but it's working from "index.html", so it would be just templateUrl: "template/file.html" and everything works as expected.

  • what I don't know is why it works, with the wrong path, when I run it from Node! an error would have saved me a lot of time... and yours...

Well, at least I have clarified a lot of concepts in this investigation. Thank you all!

Adri
  • 56
  • 1
  • 6
0

Thanks, Zeeshan, in the links you gave me the clue. As I told on my original message, I started following the Quick Start, but I forgot to mention I chose TypeScript over JavaScript... and that was the "mistake", because TypeScript needs Node to compile to JavaScript, as I'm guessing for the results I get:

  • the TypeScript project only runs after executing it in Node via console ("npm start") and not in Apache, that doesn't get all the Angular part (it gets the tag <whatever></whatever> but doesn't translate it into the content <whatever><h1>Hey</h1></whatever>)
  • with JavaScript it works "as always", without need of a server, as you were telling me

So I'll have to choose between using TypeScript (and all the official documentation!) and host it in some platform like Heroku or work with JavaScript without needing an specific server so I can still work with Apache.

Adri
  • 56
  • 1
  • 6