Exploring the differences between using a local controller in Angular's MdDialog modal versus displaying a shadow at

I've been attempting to utilize an app-level controller to showcase a modal dialog. The local function controller tests are functioning flawlessly, but the app level controller is only showing a grey shadow instead of the expected dialog.

The edit and delete results (in this scenario) should act similarly, but they're not doing so.

Here's the Plunker link

Thank you in advance for your help.

index.HTML

 <!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Sandbox Angular</title>
    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <!-- Content CSS -->
    <link rel="stylesheet" href="Content/angular-material.css">
    <link rel="stylesheet" href="Content/ui-grid.css">
</head>
<body>
    <div class="container">
        <div ng-controller="HeaderGridCtrl">
            <div class="grid" ui-grid="gridOptions" ui-grid-edit ui-grid-resize-columns></div>
        </div>
    </div>
        <!-- /.container -->
    <script src="Scripts/angular.js"></script>
    <script src="Scripts/angular-material/angular-material.js"></script>
    <script src="Scripts/angular-animate/angular-animate.js"></script>
    <script src="Scripts/angular-aria/angular-aria.js"></script>
    <script src="Scripts/ui-grid.js"></script>
    <script src="app/app.module.js"></script>
</body>
</html>

testEdit.HTML

<md-dialog>
<div>
    <form ng-cloak>
        <md-toolbar>
            <div class="md-toolbar-tools">
                <h2>{{firstName}} {{lastName}} ({{action}})</h2>
                <span flex></span>
            </div>
        </md-toolbar>
        <md-dialog-content>
            <div class="md-dialog-content">
                <p>
                    Life's actions....make sure the juice is worth the squeeze.
                </p>
            </div>
        </md-dialog-content>

    </form>
</div>

testDelete.HTML

<md-dialog>
<div ng-controller="DetailRecordCtrl">
    <form ng-cloak>
        <md-toolbar>
            <div class="md-toolbar-tools">
                <h2>{{firstName}} {{lastName}} ({{action}})</h2>
                <span flex></span>
            </div>
        </md-toolbar>
        <md-dialog-content>
            <div class="md-dialog-content">
                <h2>{{firstName}} {{lastName}} ({{action}})</h2>
                <p>
                    Life's actions....make sure the juice is worth the squeeze.
                </p>
            </div>
        </md-dialog-content>
    </form>
</div>

app.module.js

(function () {
'use strict';
//,'ui.router''ngGrid'
var app = angular.module('app', ['ngMaterial', 'ui.grid', 'ui.grid.resizeColumns']);

app.controller('DetailRecordCtrl', ['$scope', '$mdDialog', 'action', 'currentRow', initDetail])
app.controller('HeaderGridCtrl', ['$scope', '$mdDialog', initGrid]);
app.controller('testDialogCtrl', ['$scope', '$mdDialog', initModalTest]);

//---------------------------------
app.run([function () {
    /* Run is when the app gets kicked off*/
    console.log("Run processed");
}])

//---------------------------------
function initDetail($scope, $mdDialog, action, currentRow) {
    $scope = $scope;
    $scope.action = action;
    $scope.firstName = currentRow.entity.firstName;
    $scope.lastName = currentRow.entity.lastName;
    $scope.closeDialog = function () {
        $mdDialog.hide();
    };
}

//---------------------------------
function initGrid($scope, $mdDialog) {
    var currentRow = 0;

    $scope.showDelete = function (ev, keyAction, row) {
        $mdDialog.show({
            locals: { action: keyAction, currentRow: row },
            controller: 'DetailRecordCtrl',
            scope: $scope,
            preserveScope: true,
            targetEvent: ev,
            clickOutsideToClose: true,
            skipHide: true,
            fullscreen: $scope.customFullscreen // Only for -xs, -sm breakpoints.
        })
    };

    $scope.showEdit = function (ev, keyAction, row) {
        $mdDialog.show({
            locals: { action: keyAction, currentRow: row },
            controller: LocalDetailRecordCtrl,
            templateUrl: 'testEdit.html',

            scope: $scope,
            preserveScope: true,
            ariaLabel: 'Edit Record',
            targetEvent: ev,
            clickOutsideToClose: true,
            fullscreen: $scope.customFullscreen // Only for -xs, -sm breakpoints.
        })

    };

    $scope.editIcon = '<button class="md-primary md-raised" ng-click="grid.appScope.showEdit($event,\'EDIT\',row)">EDIT</button> ';
    $scope.deleteIcon = '<button class="md-primary md-raised" ng-click="grid.appScope.showDelete($event,\'DELETE\',row)">DELETE</button>';
    $scope.info = [{ firstName: "Jimmy", lastName: "John", grade: '1st', contributionDay01: 5.12, total: 0 },
                    { firstName: "Jane", lastName: "Pauley", grade: '2nd', contributionDay01: 4, total: 0 },
                    { firstName: "Andrea", lastName: "Kragel", grade: '3rd', contributionDay01: 11.28, total: 0 },
                    { firstName: "Zebra", lastName: "Zoo", grade: 'PK', contributionDay01: 19.23, total: 0 },
                    { firstName: "Jaguar", lastName: "Meowser", grade: 'K', contributionDay01: 25, total: 0 }];
    $scope.gridOptions = {
        data: 'info',
        enableFiltering: true,
        enableColumnResizing: true,
        enableSorting: false,

        enableRowHeaderSelection: true,
        enableColumnMenus: true,
        enableCellEditOnFocus: true,
        enableRowSelection: true,
        enableCellEdit: true,
        noUnselect: false,
        cellTemplate: '<div ng-repeat="col in renderedColumns"></div>',

        columnDefs: [
            {
                field: 'wrkDisplay', displayName: 'Actions', enableCellEdit: false, width: '*'
                , cellTemplate:
                    '<div class="testClass">' + $scope.editIcon + ' ' + $scope.deleteIcon + ' ' +
                    '</div>'
            },
            { field: 'firstName', displayName: 'First Name', enableCellEdit: true, minWidth: 100, },
            { field: 'lastName', displayName: 'Last Name', enableCellEdit: true, minWidth: 100 },
            { field: 'grade', displayName: 'Grade', enableCellEdit: true, minWidth: 70 },
            { field: 'getFullName()', displayName: 'Teacher', enableCellEdit: true, minWidth: 100 },
            { field: 'contributionDay01', displayName: 'Day1', enableCellEdit: true, minWidth: 50, cellFilter: 'number: 2' },
            { field: 'getTotal()', displayName: 'Total', enableCellEdit: false, cellFilter: 'currency' }]
    };

    //Calculated fields
    angular.forEach($scope.info, function (row) {
        row.getTotal = function () {
            return this.contributionDay01 * 11;
        }
        row.getFullName = function () {
            return (this.firstName + ' ' + this.lastName);
        }

    });

    function LocalDetailRecordCtrl($scope, $mdDialog, action, currentRow) {
        $scope.action = action;
        $scope.firstName = currentRow.entity.firstName;
        $scope.lastName = currentRow.entity.lastName;
        $scope.closeDialog = function () {
            $mdDialog.hide();
        }
    };

}
})();

Answer №1

Finally found the solution by revisiting the Angular $mdDialog documentation for the nth time.

Realized that the controller specified in the $mdDialog.show method can be either declared with or without quotes.

  • If declared without quotes, it uses the local $scope function.
  • If declared with quotes, it uses the app level controller (e.g., app.controller(...)) and allows for the use of template/templateUrl.

This discovery now allows for a single HTML detail record page to be accessed from multiple data points if needed.

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

The use of `await` within a loop may not function as anticipated when the code is being run through Puppeteer, yet it functions flawlessly when executed in the browser's console

Currently, I am assessing the functionality of the codeToBeEvaluated function within a browser environment using puppeteer. Within codeToBeEvaluated, there is a while loop designed to trigger an alert (referenced as LINE B) every 10 seconds. The issue ari ...

how to create a smooth transition back to the original state after a click event

I've put in a lot of effort to make sure my code for the DECAY shapes is correct up to this point. The click event I implemented makes the shapes gradually start being affected, just as I intended. However, once I release the mouse or finger, it insta ...

Synchronizing timers among different elements

Just a little context: I'm diving into the world of React and currently working on a small app using next.js (with a template from a tutorial I followed some time ago). Lately, I've encountered a challenge where I need to synchronize a timer betw ...

using a ternary operator within the map function

Currently, I'm developing a web application that allows users to view a list of items and mark certain items as favorites. The favorites are stored in an array of IDs assigned to a prop (this.props.favorites). To ensure there are no duplicate entries, ...

The CSS style of the Div element is not being displayed properly when embedded with JavaScript

Currently, I am working on a simple page for practice purposes. The main issue I am facing is with a div element that has a red border and a blue background. Inside the div, there is a script tag calling an external JavaScript file. Surprisingly, the JavaS ...

The functionality of $viewContentLoading appears to be malfunctioning

Before the content is loaded, I'm attempting to log a value. I am using $viewContentLoading within the init function, but the value is not being logged. Can anyone help me identify the issue with my code? var app = angular.module('plunker&apos ...

Unable to replicate the functionality of the tab key using jQuery for the enter key

How can I focus on the first input ('Qtd on the table') after pressing enter on the 'Buscar' input? I've tried various solutions like $(this).nextAll('input').first().focus(); $(this).next('input:text').focus ...

What sets apart calling an async function from within another async function? Are there any distinctions between the two methods?

Consider a scenario where I have a generic function designed to perform an upsert operation in a realmjs database: export const doAddLocalObject = async <T>( name: string, data: T ) => { // The client must provide the id if (!data._id) thr ...

Tips for Organizing an Array: Grouping Categories and Products

I have a single array and I am looking to separate categories from the products listed within it. const product = [{ id: 1, name: 'Cloth', cat: ['fashion', 'man', 'women'] }, { id: 2, name: &apos ...

Preserve the wpColorPicker selection using personalized knockout bindings

Utilizing wpColorPicker and knockout, my goal is to update the color picker value in my observable and then store it in the database as JSON. While other elements successfully update and save, there seems to be an issue with my custom binding for the data ...

In React.js, the switch case statement consistently defaults to the default case

Currently, I am working on utilizing <select> tags to update information across components using useContext(). However, I am encountering an issue where the default case is consistently being returned despite the fact that the logged values match the ...

Turn off auto-suggestion feature on the iPad and iPhone keyboard using JavaScript

I'm facing a challenge where I want to turn off the predictive suggestions and autocorrect feature on the iPad keyboard. This image is just for display purposes and not from my actual project. I need to hide the highlighted suggestion bar, and I am u ...

Creating an original list by iterating through a given list

I understand that some may consider this a duplicate, but I have yet to come across a similar example that I can relate to with my limited knowledge. So, I apologize in advance :) This should be pretty simple for an experienced JS developer, I assume. My ...

The initial number is inserted within the text box upon entering the final number

Whenever I enter the final digit, the text-box swallows up the initial number (it vanishes), resulting in an additional space. https://i.stack.imgur.com/Vfm8s.png https://i.stack.imgur.com/od4bQ.png Upon clicking outside of the text-box, the formatting ...

Stop users from saving the page in Next.js

I'm currently working on a NextJs project that involves building an editor application. I want to ensure that the editor functionality does not work when users attempt to save the page in a different format, similar to how applications like Youtube an ...

Generate and store text inputted from contenteditable

As I embark on creating my own custom rich text editor, I have a couple of questions regarding its functionality. First and foremost, is it possible to prepopulate the text area with content? Additionally, I'm seeking guidance on how to save and utili ...

Utilize a single WebAssembly instance within two separate Web Workers

After compiling a wasm file from golang (version 1.3.5), I noticed that certain functions using goroutines are not supported. When these functions are called, they run in the current thread and slow down my worker significantly. To address this issue, I w ...

Error: string literal left incomplete with spaces only

I am attempting to run parameters from a JavaScript function, but I am encountering an issue with quotes when there is a white space present. This error specifically pertains to Mozilla: SyntaxError: unterminated string literal Below is the relevant p ...

Adding a class to a PHP file using AJAX response

I have been developing a website that features a like button attached to user-generated posts. My goal is to update the like count of a post whenever a user likes it, but I am encountering an issue where the entire post gets affected. Below is the code fo ...

Iterating through elements within a Div will retrieve the initial element exclusively

Is there a way to loop through all elements within the MainDiv Div in order to retrieve their values? Currently, I am only able to retrieve the value of the first element. <div id="MainDiv"> <input type="text" id="MyText"value="Text1" /> ...