maria maria - 21 days ago 5x
AngularJS Question

Would angularjs work locally?

Would pure angular and css/html work in a local machine?

In my case, I'm not getting any errors, but at the same time the messages won't show any output. Any idea why?

Some of the code:

<link rel="stylesheet" type="text/css" href="/C:somethinghere\style.css">

<script src=""></script>
<script src="/C:somethinghere\app.js"></script>


<body class="parent" ng-app="myApp">
{{ messages }}


var myApp = angular.module('myApp',[]);

myApp.controller('GreetingController', ['$scope', function($scope) {
$scope.messages = "hello";
$scope.ratings = [{test: 22},{test: 99}];

NOTE: the links are correct, i just changed the links to now show my username.


The answer is: Yes, angular works on a local machine.

The problem in your code is that you are not assigning the controller to the view, you are missing the ng-controller="GreetingController" inside your view.

So to fix that, just enclose {{ messages }} inside a div tag with ng-controller attribute.

A solution might look like that:

<body class="parent" ng-app="myApp">
   <div ng-controller="GreetingController">
      {{ messages }}

Also, please notice that in your HTML, you opened a <body> tag but you closed it with </div> tag. You missed the </body> enclosing tag and you missed a <div> opening tag.

Another small tip:

Try to use relative paths instead of absolute paths when you load CSS/JS files.

Just write <link href='styles/style.css'> instead of <link href='c:/.../styles/style.css'>. This path assumes that you have a styles folder in the same folder that your HTML file exists.