Design a table within an mdDialog that allows for editing of data presented in JSON format

I'm attempting to implement a dialog using JSON data.

        $scope.showAttributeData = function(data) {
        $scope.feature = data
        console.log($scope.feature)
        var that = this;
        var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && that.customFullscreen;
        $mdDialog.show({
                locals: {
                    feature: $scope.feature
                },
                controller: attributeDialogController,
                controllerAs: 'attributeDialog',
                templateUrl: 'attribute-dialog.template.html',
                parent: angular.element(document.body),
                clickOutsideToClose: true,
                hasBackdrop: false,
                fullscreen: useFullScreen,
                openFrom: angular.element(document.querySelector('#left')),
                closeTo: angular.element(document.querySelector('#left'))
            });
        $scope.$watch(function() {
            return $mdMedia('xs') || $mdMedia('sm');
        }, function(wantsFullScreen) {
            return that.customFullscreen = wantsFullScreen === true;
        });
    };

However, in the template, the data does not render. It seems like the template is not receiving the data from the controller.

 <script type="text/ng-template" id="attribute-dialog.template.html">
            <md-dialog id="attribute-dialog">
                <md-toolbar>
                    <div class="md-toolbar-tools">
                        <h2>Attribute Information</h2>
                        <span flex></span>
                        <md-button class="md-icon-button" ng-click="attributeDialog.close()">
                            <md-icon md-svg-src="img/icons/ic_close_24px.svg" aria-label="Close dialog"></md-icon>
                        </md-button>
                    </div>
                </md-toolbar>
                <md-dialog-content>
                    <div class="md-dialog-content">
                        <table>
                            <thead>
                                <tr>
                                    <th>Attr</th>
                                    <th>Value</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ng-repeat="(key, value) in feature">
                                    <td> {{key}} </td>
                                    <td>
                                        <input type="text" ng-model="feature[key]"/>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </md-dialog-content>
                <md-dialog-actions layout="row">
                    <span flex></span>
                    <md-button type="submit" ng-click="attributeDialog.close()" class="md-raised md-primary">OK</md-button>
                </md-dialog-actions>
            </md-dialog>
        </script>

Could it be something else? Additionally, both the dialog template and controller are relatively new. In the future, I plan to incorporate editable information with ng-model. If anyone knows how to do this correctly, please let me know. I am passing information from a leaflet map.

mainLayer.eachLayer(function(layer) {
        layer.on({
            click: function() {
                var scope = angular.element($("#main")).scope().showAttributeData(layer.feature.properties);
            },
        });
    });

Furthermore, I recently started learning Angular a week ago. If you notice any errors or mistakes in the code, please feel free to point them out. Thank you!

Answer №1

To assist you with your markup, I have prepared a test example - CodePen

Markup

<div ng-controller="MyController as vm" ng-cloak="" ng-app="app">
  <md-button class="md-primary md-raised" ng-click="vm.open($event)">
    Custom Dialog
  </md-button>

  <script type="text/ng-template" id="test.html">
        <md-dialog id="attribute-dialog">
        <md-toolbar>
          <div class="md-toolbar-tools">
            <h2>Attribut info</h2>
            <span flex></span>
            <md-button class="md-icon-button" ng-click="attributeDialog.close()">
              <md-icon md-svg-src="img/icons/ic_close_24px.svg" aria-label="Close dialog"></md-icon>
            </md-button>
          </div>
        </md-toolbar>
        <md-dialog-content>
          <div class="md-dialog-content">
            <table>
              <thead>
                <tr>
                  <th>Attr</th>
                  <th>Value</th>
                </tr>
              </thead>
              <tbody>
                <tr ng-repeat="(key, value) in feature">
                  <td> {{key}} </td>
                  <td>
                    <input type="text" ng-model="feature[key]"/>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </md-dialog-content>
        <md-dialog-actions layout="row">
          <span flex></span>
          <md-button type="submit" ng-click="attributeDialog.close()" class="md-raised md-primary">ОК</md-button>
        </md-dialog-actions>
      </md-dialog>
  </script>
</div>

JS

angular.module('app',['ngMaterial'])

.controller('MyController', function($scope, $mdDialog) {
  this.open = function(ev) {
    $scope.feature = {
      blah: "blah",
      yah: "yah"
    }
    $mdDialog.show(
      {
        templateUrl: "test.html",
        clickOutsideToClose: true,
        scope: $scope,
        preserveScope: true,
        controller: function($scope) {
       },
    });
  };
})

Answer №2

Experience the power of targeting events:

 $scope.displayAttributeData = function(data,event) {
    $scope.feature = data
    console.log($scope.feature)
    var that = this;
    var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && that.customFullscreen;
    $mdDialog.show({
            locals: {
                feature: $scope.feature
            },
            controller: attributeDialogController,
            controllerAs: 'attributeDialog',
            templateUrl: 'attribute-dialog.template.html',
            targetEvent: event,
            parent: angular.element(document.body),
            clickOutsideToClose: true,
            hasBackdrop: false,
            fullscreen: useFullScreen,
            openFrom: angular.element(document.querySelector('#left')),
            closeTo: angular.element(document.querySelector('#left'))
        })
        .then(function(credentials) {
            return that.showToast("Welcome, " + credentials.username + ".");
        });
    $scope.$watch(function() {
        return $mdMedia('xs') || $mdMedia('sm');
    }, function(wantsFullScreen) {
        return that.customFullscreen = wantsFullScreen === true;
    });
};

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

Add the component view to the webpage's body section

Using Angular 7 and ngx-bootstrap 4.0.1 Dependencies: "bootstrap": "3.3.7", "bootstrap-colorpicker": "2.5.1", "bootstrap-duallistbox": "3.0.6", "bootstrap-markdown": "2.10.0", "bootstrap-progressbar": "0.9.0", "bootstrap-slider": "9.8.0", "bootstrap-tags ...

A variable must be defined within a specific block in order to be recognized

In an effort to enhance my code within a passport function, I am looking to pull values from a mongodb Database rather than from an array. The initial functioning code appeared as follows: passport.use( new LocalStrategy( { usernameField: ...

Utilizing window.location.pathname in Next.js for precise targeting

Are you familiar with targeting window.location.pathname in NEXT.JS? I encountered a red error while using this code in Next.js const path = window.location.pathname console.log(path) // I am able to retrieve the pathname here Then { ...

Are you curious about the array of elements in React's carousel?

I'm currently in the process of constructing a website using React, and I have a specific challenge related to the "news" section. Within this section, I have a list of three components that represent different news items. These components are housed ...

The route seems to be downloading the page instead of properly rendering it for display

I'm facing a simple issue with my Express page - when I navigate to the FAQ route, instead of displaying the page it downloads it. The index page loads fine, and the FAQ page is the only other page available at the moment. I am using EJS templating, a ...

Converting HTML elements into Vue.js Components

In my Vue.js application, I am utilizing a d3.js plugin to generate a intricate visualization. I am interested in implementing a customized vue directive to the components that were incorporated by the d3 plugin. It seems that the $compile feature, which ...

Generate HTML on the fly using Node variables

Utilizing Node.js with Express as the server, I have implemented a feature where users can upload .CSV files containing data. This data is then parsed and stored in a main array made up of arrays, with each line representing one array element. Currently, I ...

Retrieving JSON data from outside the React root directory

My current project includes an older javascript/php application with numerous JSON files used to retrieve data from the database. As I plan to migrate some modules to React, I am wondering if it's possible to still fetch data from these JSON files wi ...

Is it possible to utilize Vue's splice method within a forEach loop in order to delete multiple elements at

I am currently working on an image grid in array form. I am trying to implement a multi-deletion functionality. When a checkbox for each image in the grid is checked, I store the selected image's index in an array called selectedImages. Upon clickin ...

Can content be dynamically loaded through ajax in Simile Timeline instead of being loaded upfront?

I am currently utilizing the JavaScript Simile Timeline which includes timeline items with extensive description fields. Rather than including all this information in the initial JSON payload data, I only want to load it when a user clicks on a timeline it ...

Having trouble seeing the output on the webpage after entering the information

I can't seem to figure out why the result is not displaying on the HTML page, so for now I have it set up as an alert. <h1>Factorial Problem</h1> <form name="frm1"> Enter any number :<input type="text" name="fact1"& ...

Is the new mui LoadingButton not available in the latest version?

According to the material UI documentation found at here, you are supposed to import LoadingButton from '@material-ui/lab/LoadingButton'; However, I am unable to locate this folder within mui/lab and the import statement is resulting in an erro ...

How can I replay an HTML audio element?

I created an HTML5 page with an audio element for playing music in mp3 format. However, when the music plays to the end, it stops and I'm using JavaScript to control the audio element. Even so, I can't seem to replay it, only stop it. Is there a ...

Using Node modules in the browser: A beginner's guide

Once you've used npm to install packages such as: $ npm install bootstrap or $ npm install angular these packages are typically stored in the "node_modules" directory. The question now arises, how do you link to or access them from an HTML page? U ...

The required element was not discovered

Whenever I attempt to execute npm run serve, it reaches 98% completion and then halts, displaying the following error message: An issue occurred while compiling with a total of 1 error: ...

Integrate a @Component from Angular 2 into the Document Object Model of another component

One of my components is called TestPage import { Component } from '@angular/core'; @Component({ selector: 'test-component', template: '<b>Content</b>', }) export class TestPage { constructor() {} } Another ...

Encountering invalid parameters while attempting to utilize the track.scrobble service from the Last.Fm API in a Node.js application

After successfully completing the Last.Fm authentication process following the instructions provided here, I received the session key without any issues. However, my attempts to make an authenticated POST request to the track.scrobble method of the Last.Fm ...

Retrieve a Play Scala variable in the $scope of an AngularJS application

After trying various methods recommended on StackOverflow, I am still struggling to retrieve a Play Scala variable within my Javascript $scope. The line of initialization in an HTML file is as follows: @(playVariable: String)(implicit request: play.api.mv ...

JavaScript is a powerful tool for reading JSON files

I'm trying to figure out how to parse a nested object in JSON using JavaScript. Here's the code I have so far: var myRequest = new Request('test.json'); fetch(myRequest) .then(function(response) { return response.json(); }) .then( ...

Exploring Angular2's ability to interpret directive templates using the ng-container

Recently delving into angular2, I ventured into creating dynamic forms and generating fields by following the guide provided in this URL. The result was as expected. The dynamic form component renders each field one by one using ng-container, like shown b ...