Sunday, February 3, 2019

javascript - HTML not importing Angular.js functions




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:




  1. Download WampServer

  2. Start running WampServer


  3. Copy your files to the following folder: "C:\wamp\www\"

  4. Change the "src" of your script file in your HTML page to the new location.

  5. 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...