AngularJS works on Netbeans but not on a file

18 views
Skip to first unread message

Alejandro Barrero

unread,
Dec 6, 2014, 5:05:31 PM12/6/14
to ang...@googlegroups.com
The HTML
<!DOCTYPE html>
<head>
    <title>Hello World, AngularJS</title>
</head>
<body ng-app>
    Enter greeting:
    <input type="text" ng-model="greeting" />
    <p>Hello <span ng-bind="greeting"></span>!</p>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
</body>
</html>
Runs fine in NetBeans, but when I put it in a file iot fails in the browser.  I am learning AngularJS so I don't know what I am missing.

Your help will be greatly appreciated,

Alejandro Barrero

Justin Walsh

unread,
Dec 7, 2014, 2:55:24 AM12/7/14
to ang...@googlegroups.com
Hi Alejandro

I'm guessing that when you use netbeans that it is starting up some sort of http server that you then point to.  (Just guessing since I don't use netbeans).
If that is the case:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>

.. resolves to http://ajax.googleapis.com/..... (which exists).

Now, if you try to run it as a file, the above will resolve to file://ajax.googleapis.com/....  which obviously doesn't exist.

Just one of the pitfalls of using a file based approach.  There are others too (CORS etc).

My recommendation is to avoid the file based approach and either use:
  • Your IDE
  • A simple node (express) server
  • A plnkr

Regards
Justin

Alejandro Barrero

unread,
Dec 7, 2014, 6:33:39 AM12/7/14
to ang...@googlegroups.com
You are absolutely right; thank you very much.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/sJO_Hci8usY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Sincerely,

Alejandro Barrero
Reply all
Reply to author
Forward
0 new messages