The absence of a function definition within a controller is a common issue in AngularJS

I have been attempting to run a function once a video finishes playing. The function is located within an angular controller, but I am encountering an error message that reads:

ReferenceError: postVendor is not defined

Below is the JavaScript code where the function is being called:

        $.noConflict();
        jQuery(document).ready(function ($) {
            var api = flowplayer();
            api.bind("finish", function (e, api) {
                var data = "true";
                var url = "someurlhere";
                postVendor(url, data);
            });
        });

Here is the module/controller setup in the same file:

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

registrationModule.controller("vendorCtrl", function ($scope, $http) {
    $scope.postVendor = function (url, data) {
        $http.post(url, data).success(function (data) { console.log(data) }).error(function (data) { console.log(data)  });
    };

});

Within my HTML markup:

<html xmlns="http://www.w3.org/1999/xhtml" ng-app="registrationModule">

<body ng-controller="vendorCtrl">

The version of Angular I am using is 1.2.25.

If anyone has any suggestions on how to ensure the proper execution of the function, it would be greatly appreciated!

Answer №1

1. Please ensure jQuery is loaded before angular.js

2. Confirm that your vendorCtrl returns $scope.postVendor (you can achieve this by adding):

  return {
    postVendor: $scope.postVendor 
  };

Refer to the example below:

  $(document).ready(function () {
    
     
     angular.element('#angularController').controller().doSomthing("Hello ", "from jquery")
  
  });
  

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

app.controller('firstCtrl', function($scope){

  $scope.doSomthing = function(a,b){
    alert(a+b);
  };
  
 return {
    doSomthing: $scope.doSomthing
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


<body ng-app="app"  >
  <div id="angularController" ng-controller="firstCtrl">

      </div>
</body>
This should be helpful

$.noConflict();
jQuery(document).ready(function ($) {
    var api = flowplayer();
    api.bind("finish", function (e, api) {
        var data = "true";
        var url = "someurlhere";
        angular.element('body').controller().postVendor(url, data);
    });
});

For more information, please visit Call Angular JS from legacy code

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

Is it possible for a Vue data property to have a value that is determined by another Vue data property object?

Within my HTML form, I have implemented the flatPickr (calendar picker) component which generates an input field. I am currently exploring how to dynamically change the class of the input field if the error class function returns true. Below is the flatPi ...

How can I attach a jQuery plugin to a textbox with a changing class name?

I have a function that converts a regular text field into a datepicker: <input type="text" class="datepicker form-control" name="text-150" > var DatePicker = function () { if ($(".datepicker").length === 0) { return; } $(".datepic ...

Unexpected behavior: jQuery AJAX request isn't triggering the alert function as expected

I can't figure out why this code isn't working: $.get("/some/url/", function(event) { alert('hey'); }); When I click the button, I can see the response being executed in the Firefox console, and it shows a successful status (200 O ...

Authentication using the MVC standard combined with webApi

I'm in the process of creating an Angular SPA application that will utilize MVC WebApi methods with authorization attributes. I need to incorporate an authentication mechanism, which leads me to my question: Should I transfer the standard accountCon ...

Is it possible to establish a scope for jquery.ajaxSetup()?

Currently, I am working on a project involving numerous ajax calls with repetitive parameters. After some consideration, I am contemplating using jquery.ajaxSetup() to streamline the code. However, jQuery does not recommend this approach in their API docu ...

To identify the dynamically inserted and generated div element amidst the other elements on the page

My goal is to have a new div generated and inserted over the other elements on the page when a button is clicked. Here is the markup I've written: <div id="parent"> <div id="d1"> </div> <div id="d2"> </div&g ...

Are there any plugins available that can create a Ken Burns effect using JQuery?

All I need is a straightforward plugin, not one for creating slideshows. In this case, I only have 1 div and 1 image. The goal is to have the image animate within the div, shifting left/right or up/down without any white space visible. The size of the ima ...

What is causing the sorting table to fail in React when using useState?

import React, { useState } from "react"; import "./App.css"; const App = () => { const [data, setData] = useState([ { rank: 1, name: "John", age: 29, job: "Web developer", }, { rank: 2, name: "Micha ...

LeafletJS tiles are only loaded once the map is being actively moved

Currently, I am facing an issue while trying to load a simple leaflet map in my Ionic 2 application. The problem is that not all tiles are loading correctly until the map is moved. this.map = new L.Map('mainmap', { zoomControl: false, ...

Encountering a Template Parse Error after running the ng build --prod command

As a newcomer to Angular, I have successfully created a small application that requires a sortable table. Everything works well in Angular-cli development server during development mode (using ng serve). I've experimented with implementing the table ...

Netbeans lacks compatibility with JavaScript

Recently, I've been encountering code errors in my .js files while attempting to edit JavaScript using Netbeans 6.9. Even after upgrading to Netbeans 7.01 and enabling the JAVA plugin, the issue persists. I'm unable to create a new JavaScript tem ...

Is it advisable to Utilize ES6 Classes in Javascript for Managing React State?

Is it recommended to use ES6 classes directly as React state? I am interested in creating an ES6 class that: Contains member variables that will trigger re-renders on the frontend when changed. Includes methods that sync these member variables with the ...

Functionality in Three.js that involves selecting nearby objects with an event handler and ensuring that the self object is

I have spent countless hours today diving deep into the documentation, tutorials, and stackoverflow questions in pursuit of a solution to this issue. I am pleading for your assistance – please take pity on me and help! The problem at hand involves a wat ...

Framer Motion's "repeatType" property triggering a TypeError

Every time I try to add the repeatType property in my transition, I encounter an error related to the variants prop: index.d.ts(2779, 5): The expected type comes from property 'variants' which is declared here on type 'IntrinsicAttributes ...

Are there any techniques for running unit tests on a Vue.js transition?

I have been working on a Vue component that includes a transition with a dynamically generated name. My challenge is to test whether the transition name is correctly set based on the props I pass into the component. Below is the code snippet of the compone ...

What is the process for swapping out a file input tag with a specific file already chosen?

As I attempt to process a file one line at a time, I came across this helpful solution. Unfortunately, the method involves using a file input tag to choose a file for reading. I am in search of a way to bypass the file input tag and specify a file in advan ...

Having trouble retrieving mobiscroll instance in Angular with Ionic

I'm facing an issue with accessing the instance of my mobiscroll widget in Angular 4 with Ionic Framework. Despite following all the correct steps, the actual widget won't get selected. Below is the code for the widget: <mbsc-widget [options ...

Is it necessary to enable validation for an Angular reactive form toggle?

Can you help with this issue I'm having? I have a radio button that asks the user if they have a massage certificate. If they answer yes, a file input should be displayed. By default, the file input should not be required, but if the user selects yes, ...

What is the best way to transform a JavaScript file retrieved from a remote server (returned as a string) into a standard JavaScript object in a Node

Is there a way to convert a JavaScript file fetched from a remote server (which is in string format) into a regular JavaScript object in Node.js? I know that I can use JSON.parse to convert a JSON string into a dictionary, but in this case, the file contai ...

Encountering an unexpected token in Javascript when using conditionals

I am currently attempting to integrate a JavaScript condition within a listed order, containing two radio buttons that need to be checked in order to progress to the following list based on the selection. <li data-input-trigger> <label class="fs- ...