I am using an HTML page to call functions from an Angular.js page using $scope. No matter what i do, my result appears as {{heading + message}} instead of Hello (+) Users name. (see code below). I feel like this is an issue with not being able to call from my js file, or simply not being able to call the Angular library.
I tested out an example from the Angular.js website and it worked fine so i assume it cannot call the file. I have tried relative paths and direct paths, but neither seem to work for calling the first.js file.
Could it be a problem with not running a node.js server?
Here is the HTML and JS code (my code works perfectly on Stackflow's tester but not on my computer)
var firstApp = angular.module('firstApp', []);
firstApp.controller('FirstController', function($scope) {
$scope.first = 'Some';
$scope.last = 'One';
$scope.heading = 'Message: ';
$scope.updateMessage = function() {
$scope.message = 'Hello ' + $scope.first +' '+ $scope.last + '!';
};
});
Name App
Name:
{{heading + message}}
Answer
AngularJS doesn't do its job if you don't run it on a server.
If you're not familiar with running a webpage on a server, follow these steps:
- Download WampServer
- Start running WampServer
- Copy your files to the following folder: "C:\wamp\www\"
- Change the "src" of your script file in your HTML page to the new location.
- Open up a browser and go to http://localhost/app.html (assuming your HTML-file is called app.html)
AngularJS will now be able to do its job, just like on StackOverflow.
No comments:
Post a Comment