What could be causing my controller to show {{message}} instead of the message that was set up in the configuration

<!DOCTYPE html>
<html>
<head>
      <script src="js/angular.js"></script>
      <script src="js/Script.js"></script>
</head>
<body ng-app="LoginPage" ng-controller = "LoginPageController">
    <form action = "next.html" ng-submit="fun1($event)">
    username : <input name = "username" ng-model="un">
    <div>{{message1}}</div>
    password : <input type = "password" name = "password" ng-model="pw">
    <div>{{message2}}</div>
    <input type = "submit" value = "login">
    </form>
</body>
</html>

I am currently working on developing a simple login page using AngularJs. Unfortunately, I have encountered an issue where the browser is not displaying the expected scope message, but rather showing the tag as {{message}}.

//defining a new module
var loginPage = angular.module("LoginPage",[]);

//attaching the controller to the module
loginPage.controller("LoginPageController",function ($scope){
$scope.un = "";
$scope.pw = "";
$scope.message1="";
$scope.message2="";


$scope.fun1 = function(e){;
if($scope.un.length == 0){            //verifying length
$scope.message1 = "Please enter your username";   //verification message 1
e.preventDefault();
}else{
$scope.message1=""; // verification message 2
}
if($scope.pw.length == 0){
$scope.message2 = "Please enter your password";
e.preventDefault();
}else{
$scope.message2="";

}
}});

Answer №1

Your code is missing the proper inclusion of Angular JS. Please make sure to add it correctly using the provided working version below:

I made a modification to the following line:

 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

If you prefer to use a downloaded version of the Angular library, double-check your file path and name.

//creating a module
var loginPage = angular.module("LoginPage",[]);

//registering the above controller to the module
loginPage.controller("LoginPageController",function ($scope){
$scope.un = "";
$scope.pw = "";
$scope.message1="";
$scope.message2="";


$scope.fun1 = function(e){;
if($scope.un.length == 0){            //checking for length
$scope.message1 = "enter name";   //message 1
e.preventDefault();
}else{
$scope.message1=""; // message 2
}
if($scope.pw.length == 0){
$scope.message2 = "enter password";
e.preventDefault();
}else{
$scope.message2="";

}
}});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>
<head>
</head>
<body ng-app="LoginPage" ng-controller = "LoginPageController">
    <form action = "next.html" ng-submit="fun1($event)">
    username : <input name = "username" ng-model="un">
    <div>{{message1}}</div>
    password : <input type = "password" name = "password" ng-model="pw">
    <div>{{message2}}</div>
    <input type = "submit" value = "login">
    </form>
</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Compatibility issues between jQuery and AngularJS are causing problems

Currently, I am facing a compatibility issue between RequireJS and Angular in my setup. Everything functions without any problems when using jQuery version 1.7.2. However, I wanted to upgrade to jQuery 1.8.1 along with jQuery UI, but unfortunately, my Angu ...

Postman seems to be functioning correctly while AXIOS is encountering issues

I've encountered a strange issue with my MERN app. When I use Postman to send a PUT request to my API, it successfully updates both the API and MongoDB. However, when performing the same action on the front-end, the API does not update even though the ...

Currently, I am developing a customized stylesheet specifically designed for Internet Explorer versions 10 and 11

Is it possible to utilize this straightforward script for identifying IE versions 10 and 11? if($.browser.version == 11.0 || $.browser.version == 10.0) { $("body").addClass("ie"); } ...

Send a file using ajax with the help of JavaScript and PHP

Currently, I am looking to implement a method for uploading files using Ajax and JavaScript/PHP without having the page refresh. My initial thought is to use Ajax to send the file using xmlhttp.send(file) and then retrieve it in the PHP script, but I' ...

What techniques can be used to resize an image to perfectly fit a square on a webpage?

A challenge on the web page is to display images in a square format of 90 * 90 pixels. However, the sizes of these images are not consistent and may vary from 80*100 to 100*80 or even 90 * 110. The requested solution is to stretch the image as follows: ...

Streamlining a complex task in JavaScript

I am currently exploring options to streamline my code so that I don't need to repeat the same function 38 times. Instead, I would like to have a single function that can handle 38 different IDs separately. The script is designed to randomly select a ...

Next.js triggers the onClick event before routing to the href link

Scenario In my current setup with Next.js 13, I am utilizing Apollo Client to manage some client side variables. Objective I aim to trigger the onClick function before navigating to the href location. The Code I'm Using <Link href={`/sess ...

There appears to be an issue with the onmousemove function

I am currently troubleshooting an issue with a script that I wrote for my button. Interestingly, the code works flawlessly when I test it on CodePen, but I encountered an error when I attempted to run it in VSCode. Even after trying to recreate the script ...

"Resetting the state of a form in AngularJS2: A step-by

Looking to reset the form state from dirty/touched in angular? I am currently delving into the world of angular2 and working on a form with validation. In my journey, I came across this code snippet: <form *ngIf="booleanFlag">..</form> This ...

Unleashing the Power of RxJS with OR Conditions

I am working with two Observables. For instance, I am waiting for either an HTTP POST call or a WebSocket call to return so that I can proceed. Once either call returns, I need to verify the information until a certain condition is met. In the following e ...

The Google Map is not showing all the details

Our app is developed using ReactJS on Rails API, with a Google map integrated. However, when visiting this link and clicking "Map View", some grey space appears under the Google Map. An example image can be found here: example We are having trouble findi ...

Storing the state of web applications in AJAX applications

How can the application state be maintained across requests for thick JavaScript clients? In addition to client managed cookies and descriptive URLs, are there any other methods? Please note that by clients I am referring to thick JavaScript clients. The ...

Transferring attributes from grandchildren to their ancestor

My React.js application structure looks like this: <App /> <BreadcrumbList> <BreadcrumbItem /> <BreadcrumbList/> <App /> The issue I am facing is that when I click on <BreadcrumbItem />, I want to be able to ch ...

Automatically switch Twitter Bootstrap tabs without any manual effort

Is there a way to set up the Twitter Bootstrap tabs to cycle through on their own, similar to a carousel? I want each tab to automatically switch to the next one every 10 seconds. Check out this example for reference: If you click on the news stories, yo ...

Verification of custom data type validation

I am puzzled by the behavior of this custom type state: interface DataType { [key: string]: string;} const [data, setData] = React.useState<DataType>({}); When I attempt to execute console.log(data === {}) It surprisingly returns false. Why ...

What is the reason behind jshint issuing an alert specifically for the lastSelectedRow being

Upon pasting the code below into jshint.com, an error is generated: Read only in reference to line: lastSelectedRow = 1; I am curious as to why this error occurs and how it can be remedied. Interestingly, jslint does not return this error. /*global la ...

Searching through a JSON object for nested objects within objects

Currently, I have some data structured as follows: var items = [ { "id" : 1, "title" : "this", "groups" : [ {"id" : 1, "name" : "groupA"}, {"id" : 2, "name" : "groupB"} ] }, { "id" : 2, "title" : "that", ...

Tips for Adding or Deleting 2 Rows in a Table

When the basket icon on the right is clicked, I want to remove both the current <tr> and the yellow one as well. Check out this screenshot: This is the HTML code for the two rows that need to be deleted with a click: <tr> <t ...

Why Are My JavaScript GET Request Parameters Displaying as Strings Rather Than Numbers?

Currently, I am in the process of developing a REST API where one of the defined routes looks like this: router.get("/objects/:id?/:val1?/:val2?", getObject); Specifically, my request from Postman appears as follows: http://localhost:8000/objects?val1= ...

Encounter an issue while attempting to generate a multidimensional array in JQuery

I am trying to utilize jQuery to create a multi-dimensional array. Below is the code snippet I have written for reference: GiftData = []; GiftData['boxProduct'] = []; GiftData['boxName'] = jQuery('#giftbox-data .box-data').te ...