Provide the scope to the directive when calling the $uibModal.open method

I am interested in developing a custom directive that displays data based on the scope of its parent controller.

Here is the directive's JavaScript code:

(function () {
    'use strict';

    angular
        .module('blabla')
        .directive('showActiveTask', showActiveTask);

    showActiveTask.$inject = ['$uibModal'];

    function showActiveTask($uibModal) {

        return {
            //replace: true,
            restrict: 'E',
            scope: {
                taskData: '='
            },
            template: '<button type="submit"' +
            '        class="btn grey lighten-1 btn-raised white-text btn-sm"' +
            '        ng-click="open()">' +
            '    <span class="hidden-xs hidden-sm">View assigned tasks</span>' +
            '</button>',
            link: linkFunc
        };

        function linkFunc(scope, element, attrs) {
            var vm = this;
            vm.showLabel = false;
            console.log(scope);

            scope.open = function () {
                vm.modalInstance = $uibModal.open({
                    templateUrl: 'blabla.html',
                    size: 'lg',
                    controller: scope.taskData,
                    backdrop: true,
                    resolve: {
                        console.log('babla')
                        }
                    }
                }).result.then(function () {
                    console.log("wanna switch");
                });
                console.log(scope)
            };

            scope.clear = function () {
                console.log('close modal');
                vm.modalInstance.close();
            };
        }
    }
})();

And here is the controller's JavaScript code:

Whenever I try to use this directive, I encounter the error message: "Argument 'fn' is not a function, got Object". The issue seems to be that I am attempting to pass a scope object as a controller. I found a similar problem and solution at . Can anyone point out what I might be doing wrong?

Answer №1

Well, well, well. The solution was staring me in the face: simply pass the parent's controller scope as a parameter to create a modal based on it:

    scope.open = function () {
        vm.modalInstance = $uibModal.open({
            templateUrl: 'blabla.html',
            size: 'lg',
            scope: scope,
            backdrop: true,
            resolve: {
                text: function () {
                    return '<strong><p>Are you sure you want to close?</p></strong>'
                }
            }
        }).result.then(function () {
            console.log("wanna switch");
        });


    };

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

Tips for creating nested child routes in AngularJS 2 with ID:

Here is a Demo of what I'm working on. Just getting started with angularjs 2 and trying to figure things out. I want to display Twitter names that correspond to certain names using routes on the same page, specifically utilizing a second <router- ...

Struggling to display a chart using angular-chart

I am facing an issue with rendering my chart. I have followed the instructions provided on the GitHub page of angular-chart.js. I have created a plunker to showcase my problem: http://plnkr.co/edit/x7XJhxxvYMzWr3u7lBcJ?p=preview Although I can access and ...

"Using Node.js Express 4.4 to efficiently upload files and store them in a dynamically

Looking for recommendations on the most efficient method to upload a file in node.js using express 4.4.1 and save it to a dynamically created directory? For example, like this: /uploads/john/image.png, uploads/mike/2.png ...

npm package.json scripts not executing

Whenever I try to run npm start or npm run customScriptCommand, npm seems to not be executing anything on my project and just quickly returns a new line in the terminal. I attempted to solve this issue by uninstalling node and npm from my machine, then in ...

AngularJS utilizes the trustAsHtml function to enable the inclusion of specific portions of a string

In the database, I have notification data that reads: Someone has recently interacted with your post. However, I need to display the username in bold using trustAsHtml. But what if the username is: alert('xss'); This would result in the outpu ...

Challenges with displaying the appropriate user interface in the dashboard according to different roles

My current project involves rendering different UI components based on selected roles such as brands, agency, or influencer. However, despite my efforts to implement the logic for this functionality, the correct UI is not being loaded and I'm struggli ...

What is the reason behind TypeScript enclosing a class within an IIFE (Immediately Invoked Function

Behold the mighty TypeScript class: class Saluter { public static what(): string { return "Greater"; } public target: string; constructor(target: string) { this.target = target; } public salute(): string { ...

Synchronize information between mongoDB and firebase bidirectionally

My current situation: Having developed an application using React, NodeJS, and Electron, most of my users utilize the app offline. Next plans: With intentions to cater to mobile users as well, I am considering creating a mobile application using React-N ...

What is the best way to maintain carousel-caption text color consistency throughout slide transitions?

Could someone shed light on the Bootstrap 5 issue I'm facing? I need to adjust the z-index to prevent text color changes during slide animations. It should remain as 'text-light'. https://i.sstatic.net/djIjc.jpg https://i.sstatic.net/shfi ...

Who is the intended audience for the "engines" field in an npm package - consumers or developers?

As the creator of an npm library, I have included the current LTS versions of Node.js and npm in the package manifest under the engines field. This ensures that all contributors use the same versions I utilized for development: Node.js <a href="/cdn-cgi ...

jQuery form validation issue, unresponsive behavior

<!DOCTYPE html> <html> <head> <title> jquery validation </title> </head> <body> <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.min.js" type="text/javascript"> ...

Discover the step-by-step guide to creating a dynamic and adaptable gallery layout using

I have encountered an issue with my gallery where the images stack once the window is resized. Is there a way to ensure that the layout remains consistent across all screen sizes? <div class="container"> <div class="gallery"> &l ...

Is there a way to detect when the browser's back button is clicked?

As I work on supporting an e-commerce app that deals with creating and submitting orders, a user recently discovered a loophole wherein they could trigger an error condition by quickly pressing the back button after submitting their order. To address this ...

My goal is to use both jQuery and PHP to automatically populate the dropdown list

Here is my PHP code for executing a query: $host = "localhost"; $user = "root"; $pass = "abc123"; $databaseName = "class"; $con = mysql_connect($host,$user,$pass); $dbs = mysql_select_db($databaseName, $con); $result = mysql_qu ...

What is preventing me from retrieving WP custom fields value or post ID using Ajax?

After successfully generating a link based on the visitor's location, I encountered an issue with caching when using full-page caching. To address this problem, I decided to implement AJAX to dynamically load the link. While my code worked well in ret ...

What is the best way to design a new class that will serve as the parent class for both of my existing classes, allowing them

I am facing a challenge with my programming classes. I have two classes, "Player" and "Enemy", each with similar methods and properties. I want them to inherit from a parent class that I'll create called "Game Object". How can I approach creating thi ...

Retrieve Django imagefield file name using jQuery before submitting

Exploring the essential Django image file upload procedure, where the image model incorporates the ImageField class. There's a custom display button replacing the default upload button which usually showcases the image name alongside it. Hence, the ne ...

What is causing the Unhandled Rejection (TypeError) error after I move the object in my Redux application and receive the message "Cannot read property 'filter' of undefined"?

I've been working on a Redux application. I've made modifications to a couple of files, and here are the changes in the two files: index.js: const store = createStore( reducer, { propReducer: { day: 1, data: [], filte ...

Displaying API response array object in React application

Currently, I am attempting to retrieve information from an API, parse the response content, and then display it in a loop. However, I have encountered a warning message: webpackHotDevClient.js:138 ./src/App.js Line 20: Expected an assignment or function ...

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