0

Do i need to host my angular application on a node server for it to work? I have been doing local development and am trying to integrate ui.router into my application but it does not seem to work because of the root/file/file/index.html file directory when running in the browser. Is that what is causing it or is it that I need to utilize these tools with a NodeJS server for them to cooperate.

Here is what I am doing with the ui.router

      var app = angular.module("myapp",[
         'ui.router'
      ]).config(function($stateProvider, $urlRouterProvider){
      $stateProvider.state('login',{
         url:'/login',
         templateUrl:'views/login.html'
      });

Solved the problem by just running the application on my server which resolved the ui.router problem.

inoabrian
  • 3,762
  • 1
  • 19
  • 27
  • 1
    No. `angular-js` only works in the browser because it manipulates the DOM. `node.js` is a server-side JavaScript implementation with I/O functionality. – Ryan Oct 21 '14 at 06:36
  • So it has to do something with the local development and the way I am doing my url? – inoabrian Oct 21 '14 at 06:38
  • Read the tutorials on the website. – Ryan Oct 21 '14 at 06:39
  • I have read the tutorials but they mostly use it with a node app. So it still looks different and I cannot work out the kinks. – inoabrian Oct 21 '14 at 06:42
  • i am using visual-studio to run/develop angular app and it works fine. I have hosted using IIS and am not using node. – harishr Oct 21 '14 at 06:45
  • are you using ui-router at all HarishR? – inoabrian Oct 21 '14 at 06:48
  • You can certainly use it with Node.js and a HTTP framework like `express` but, you could also use PHP/Apache setup as well. – Ryan Oct 21 '14 at 06:53
  • You need a platform to bootstrap angularjs application and Node.js is one of the platform on which our angularjs application can run. You are free to use any other platform. – Vikas Garg Oct 21 '14 at 19:26

1 Answers1

4

You will need a server to run your Angular app, not necessarily a node server.

From https://docs.angularjs.org/tutorial/ :

While Angular applications are purely client-side code, and it is possible to open them in a web browser directly from the file system, it is better to serve them from a HTTP web server. In particular, for security reasons, most modern browsers will not allow JavaScript to make server requests if the page is loaded directly from the file system.

Aniket Sinha
  • 6,001
  • 6
  • 37
  • 50
  • Okay yea I had that idea what about the ui.routing any idea on how that works? – inoabrian Oct 21 '14 at 06:40
  • 1
    UI Routing will work as it is supposed to be. You just need to run your index.html file using server (not opening via a browser). If all your routing are wired correctly, then they should work as usual. – Aniket Sinha Oct 21 '14 at 06:42