Bidirectional data binding between an Angular component and its parent controller

I am currently facing an issue with an Angular component (vendor-filters) where I am trying to pass data to and from a parent controller. The goal is to create a filter based on mainInfo and update the parent controller with the filtered data. However, I am encountering a problem where the mainInfo variable is returning as undefined in the component controller. Here is the code snippet:

html

<div ng-controller="kanban as ctrl">
<vendor-filters mainInfo="ctrl.mainInfo"></vendor-filters>
<div class="qt-kb">
    <kanban-list label="Incoming" type="incoming" cards="ctrl.mainInfo.incoming"></kanban-list>
    <kanban-list label="In Progress" type="progress" cards="ctrl.mainInfo.inProgress"></kanban-list>
    <kanban-list label="Waiting For Documentation" type="docs" cards="ctrl.mainInfo.documentation"></kanban-list>
    <kanban-list label="Pending Approval" type="closed" cards="ctrl.mainInfo.closed"></kanban-list>
</div>

Parent Controller :

app.controller("kanban", ["$scope", "assignmentDataService", "globalSpinner",  function ($scope, assignmentDataService, globalSpinner) {

const vm = this;
vm.mainInfo = [];

activate();

function activate() {
    getData();
}

  function getData() {
    var promise = assignmentDataService.getData()
        .then(function(data) {
            vm.mainInfo = data;
        });

    globalSpinner.register(promise);
};

}]);

Component controller:

class VendorFilterCtrl {
constructor($http, $scope, $timeout,assignmentDataService) {
    this.$scope = $scope
    this.$http = $http;

    const vm = this;
    //I could be initializing this wrong but this is where I'm trying to get 
    //the data. 
     vm.data = vm.mainInfo;               

}
app.controller('kanban').component("vendorFilters", {
templateUrl: "app/components/vendorFilters.html",
bindings: {
    store: "=?store",
    onChange: '&',
    mainInfo: '<'
},

controller: VendorFilterCtrl,
controllerAs: "ctrl",
bindToController: true
 });

Essentially, I am attempting to transfer the mainInfo data from the parent controller to the component and vice versa. Could you provide insight into why this setup is not functioning as intended?

Answer №1

To start, ensure that kebab-case is used for the attribute:

 <vendor-filters main-info="ctrl.mainInfo"></vendor-filters>

UP NEXT

Here is what needs to be corrected:

app.controller('kanban').component("vendorFilters", {

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

What is the functionality of a nested child directive root element when placed at the same level as the parent directive root element?

Hello there, I'm currently facing a unique situation that has me stumped. Is it possible to replace the content of a directive's root element with that of a nested (child) directive? Here is an example scenario: <div id=”main”> <n ...

Incorporating a secure and personalized "tracking code" feature into a PHP web application

My web application is built using vanilla PHP and MySQL, allowing registered users to create personalized profile pages. I want to implement a textarea form field in the control panel for users to input their custom tracking code (such as Facebook Pixel o ...

Having trouble passing parameters to the Mongo find collection operation

I'm having trouble with my code where req.params only gets a value after db.collection.find is executed. Can someone help me figure out what I'm doing wrong? exports.findAll = function(req, res) { var postal = parseInt(req.params.postal); ...

Combining Flask with Ajax: AttributeError - WSGIRequestHandler does not have the attribute 'environ'

Currently, I am working on using ajax to trigger the execution of a Python file that continuously monitors changes in a text file. If any changes are detected, it will communicate back to ajax for further actions. The Python script must start running as so ...

What is the best way to import information from a CSV or Excel file directly into my program?

I am currently using puppeteer for automating a form submission process. I am looking to extract data directly from a csv file and input it into the form. Can someone guide me on how to achieve this? The CSV file contains the following information: Fir ...

JavaScript has thrown an error stating that the function in my jQuery script is undefined

I encountered an issue Uncaught TypeError: undefined is not a function in my jQuery script. Here is the code snippet: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link re ...

Testing the change in states with resolve functions in AngularJS

Testing in AngularJS is still new to me, and I'm currently working on writing tests for a $stateProvider that I've set up like this: angular.module("app.routing.config", []).config(function($stateProvider, $urlRouterProvider) { $stateProvider. ...

Having trouble with ng-click in my AngularJS Restful application

I was attempting to create CRUD operations in AngularJS. Unfortunately, I am facing an issue where my ng-click is not functioning properly. Below is the code for my list.html: <div class="container"> <input type="text" ng-controlle ...

VueJS - The application is unable to find the designated route

I've encountered an issue with the Signin page in my project. Despite having all other pages functioning properly, the Signin page doesn't seem to render anything when I navigate to it (http://localhost:8080/#/signin). import Vue from 'vu ...

What is the best way to modify a current state object without causing an endless loop of redirects?

const useCase = (argument) => { const [value, setValue] React.useState(argument) React.useEffect(() => setValue({...value ...argument), [argument, value, setValue]) } The above code is currently causing an infinite loop due to setting the stat ...

AngularJS efficiently preloading json file

I am just starting to learn about angularJS. Apologies if my question is not very clear. Here is the problem I am facing: I have a JSON file that is around 20KB in size. When I attempt to load this file using the 'factory' method, I am receivin ...

Function executed many times during click action

I have developed a web application that allows users to input any keyword or statement and receive twenty results from Wikipedia using the Wikipedia API. The AJAX functionality is working perfectly. The app should dynamically create a DIV to display each r ...

Protractor timeouts when working with AngularJS

I'm currently facing challenges with conducting end-to-end (e2e) tests using Protractor and Angularjs. I've utilized a sample test project available at the following link: https://github.com/mbcooper/ProtractorExample. Regrettably, Protractor is ...

Losing a specific characteristic of data occurs when assigning a JavaScript object

After dedicating a full day to investigating this case, I found myself losing hope. const Tests = (state = INIT_STATE, action) => { switch (action.type) { case GET_TEST_DETAIL: return { ...state, test: {}, error ...

Ways to minimize an array of objects by shared key values?

Suppose I have an array of objects structured like this: var jsonData = [ {"DS01":123,"DS02":88888,"DS03":1,"DS04":2,"DS05":3,"DS06":666}, {"DS01":123,"DS02":88888,"DS03":2,"DS04":3,"DS05":4,"DS06":666}, {"DS01":124,"DS02":99999,"DS03":3,"DS04" ...

Code: Ensuring URL spaces are maintained

In my Angular 4 project, I have a service with a delete API that requires two strings as parameters. Here is an example of how it looks: this.http.delete(this.url + 'api/v1/ReportingService/collectionID/'+ '45902' +'/'+' ...

Issue with Electron | JavaScript Runtime

Attempting to utilize WebTorrent with Electron and Node.js for torrent downloading. Here is the code snippet in main.js: const electron = require('electron') const { app, BrowserWindow } = electron const path = require('path') const u ...

What causes Angular to automatically add 'localhost' to the URL when using $location.path?

When I try to use the code below to redirect me to a specific page (redirectUrl), it instead adds 'localhost' in front of the redirectUrl resulting in "localhost/http://localhost/example/page". Is there a way to prevent this from happening? var ...

"Converting circular structure into JSON" - Inserting BigQuery Data using Cloud Function in Node.js

I am currently facing an issue while attempting to load an array of JSON objects into a BigQuery Table from a Cloud Function built in NodeJS. Despite not having any circular references, I encountered the error message "Converting circular structure to JSON ...

Data is not being successfully passed through Ajax

Having some issues with passing data through ajax. I've used this method multiple times before without any problems, but now it's not returning anything. Here is the javascript code: $('#contactformbtn').click(function(){ var full ...