AngularJS - Issue with ng-mouseover not triggering controller function

I am struggling to get a function to trigger when my button is hovered over. Despite writing what I believe is the correct code, the function from my controller is not being called. Can anyone spot the issue?

Below is the JavaScript code:

angular.module("myApp", [])
       .controller('myCtrl', function($scope) {
          $scope.alertHi = function() {
            alert('hi');
          };
       });

And here is the HTML code:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example - example-example72-production</title>

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

</head>
<body ng-app="myApp">
  <div ng-controller="myCtrl">
    <button ng-mouseover="alertHi()">
      Alert Hi
    </button>
  </div>
</body>
</html>

If you'd like to see the code in action, feel free to check out this live plunker:

http://plnkr.co/edit/ZyQUi266hFsnvPhcTcpn?p=preview

Any insights on why the function isn't firing would be greatly appreciated. Thank you!

Answer №1

code.js

angular.module("myApp", [])
       .controller('myCtrl', function($scope) {
          $scope.displayMessage = function() {
            alert('Hello');
          };
       });

Your code must be included:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8>
  <title>Sample - sample-example72-product</title>

  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.min.js"></script>
  <script scr="code.js"></script>

</head>
<body ng-app="myApp">
  <div ng-controller="myCtrl">
    <button ng-mouseover="displayMessage()">
      Display Message
    </button>
  </div>
</body>
</html>

Answer №2

Make sure you include app.js in your page's code.

<script src="./app.js"></script>

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

Invoke a function from a neighboring component using React hooks

Is there a way to call a function from another component using props or context? I've attempted to do this using props and context, but I'm getting confused as I need to pass an actual function with parameters. The goal is to invoke the handleS ...

Issues have been identified with the performance of Ionic Material List when used in conjunction with ng

In my project involving the Ionic floating menu button, everything is working fine. However, I have encountered an issue where when I click on the + button, I do not want to be able to click on the click me button while the menu is open (Req1.png)https://i ...

Using angular.js to create ng-options with personalized values

After receiving a JSON object from an AJAX call, I have the following data: 0: Object id: "0-0-0" selected: "selected" text: "option name" value: 0 __proto__: Object 1: Object id: "12-0-0" selected: "" text: "4C 1.75 16v Tb ...

When developing a node.js project using VMWare's shared folder, how can you manage the node_modules folder?

My current project needs to run on Linux, but I am using a Windows computer. This means I have to use a VM. Despite wanting to use WebStorm, I am avoiding JB Gateway due to its numerous bugs. My solution was to utilize the VMWare share folder function. Ho ...

Firebase ref.on('value') will repeatedly trigger, even if no changes have occurred

My current setup involves using an event listener to monitor changes in my real-time database. const [chats, setChats] = useState({}); const ref = db.ref(`users/${sender}/chat/`); ref.on('value', (snapshot) => { const data = snapshot ...

Enhancing the AngularJS Login feature for server authentication

Struggling to adapt Valerio Coltrè's Angular login example on GitHub to work with my ServiceStack authentication. Despite appreciating Valerio's implementation of authentication, I am facing challenges as he uses an httpBackend mock and interce ...

Django issue: A Tuple or struct_time argument is necessary

Currently, I am developing a code that deals with 2 variables - showdate and viewtype. Both of these variables are transferred via JavaScript using the POST method. viewtype = send an srt showdate = send a date from javascript Within this code snippet, ...

Integrating LinkedIn's oauth2 into an Ionic/AngularJS frontend for a hybrid mobile app, while utilizing ExpressJS, PassportJS, and MongoDB on the backend

My backend setup is on AWS and running an express webserver with configuration for passportjs. I aim for all users to log in via LinkedIn on the frontend. When they click the button, it triggers a http GET command using Angular's $http.get service. T ...

Implementing a change event upon setting a value to an input element using JavaScript

My plan is to develop a Chrome extension that can automatically fill passwords. The code for this functionality looks like the following: //get the account document.querySelector("input[type=text]").addEventListener('input', () => { ...

How can I transfer a MongoDB collection to an EJS file in the form of a sorted list?

I have successfully displayed the collection as a json object in its own route, but now I want to show the collection in a list under my index.ejs file (I'm still new to ejs and MongoDB). Below is the code that allows me to view the json object at lo ...

Using Angularjs to dynamically generate and submit tables

I can't seem to figure out this specific situation Data: $scope.MyItem = [ { "__v": 0, "myItemId": "55ed819caefe18e81ffbd2d2", "itemId": "56fec8abb192c870117ed393", "january": 1, "february": 1, ...

Encountering issues with styled component's flex not functioning as expected in React

I am currently working with styled-components, and I have been using "flex" for responsive design. However, I am facing some challenges in implementing it. The CSS defined within styled-components does not seem to be applying properly. The styles are not ...

Steps to enable navigation to external pages from a ReactJS app

I am working on a simple ReactJS application: [Demo] [Source] I am trying to implement navigation within the app from external sources without refreshing the web page. This functionality should be similar to using this.props.history.push(...). /public/i ...

Why am I getting a $injector:modulerr error while using angular-strap?

Here is my complete code: <!doctype html> <html lang="en" ng-app='myapp'> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="bootstrap/css/bootstrap.css"> ...

Dragging items in the horizontal list of Knockout-Sortable causes them to be pushed vertically

For my application development using knockout.js, I am implementing knockout-sortable to create drag-and-drop sortable lists. The setup involves a vertical list with each item containing a horizontal list. While the vertical lists are functioning properly, ...

Which is better for scrolling in Angular 2+: using HostListener or window.pageYOffset?

Which syntax is best for maximizing performance in Angular 2+? Is it necessary to use HostListener, or is it simpler to obtain the scroll position using the onscroll window event and pageYOffset? @HostListener('window:scroll', ['$event&ap ...

Input field in AngularJS not showing initial value from ng-model

I am currently utilizing ng-repeat to iterate through an array of keys and showcase the scenario value linked with each individual key. Previously, when the key value was hardcoded, the view code functioned as expected. However, now that ng-repeat supplies ...

Alexa Account Linking - Error: Account linking credentials are not valid

I've been working on setting up an Alexa skill with account linking. After obtaining the Linking Authorization Code and exchanging it for an Access Token, I attempted to input all the necessary parameters: code, access token, and skill ID into the Ale ...

Striving to design an event planner with the datepicker feature in javascript

Currently, I am integrating a javascript datepicker into my project to facilitate displaying a calendar and selecting a date for adding/viewing/editing events on that specific date. On my view, the datepicker calender is displayed within a div element. & ...

Revamping JavaScript Code for Better Performance

I've been working on a lot of code in the backend section of my website, mainly dealing with CRUD operations using AJAX calls. Do you have any suggestions on how I can refactor these functions into more generic ones or possibly create classes instead ...