material icon indicating copy to clipboard operation
material copied to clipboard

radio-button, select: throw error on $mddialog.show() and cancel()

Open jeson114 opened this issue 10 years ago • 31 comments

This happened after i updated my project to RC5 . Every time i close a dialog and try to open it ,it throws Error: [Error] [$compile:ctreq] Controller 'mdRadioGroup', required by directive 'mdRadioButton', can't be found! or Error: [Ara Error] [$compile:ctreq] Controller 'mdSelectMenu', required by directive 'mdOption', can't be found! When the respective elements are present in a form inside the dialog template capture1 capture2

jeson114 avatar Dec 03 '15 06:12 jeson114

There is no problem when i downgrade to 0.11.3

jeson114 avatar Dec 03 '15 06:12 jeson114

Please provide a CodePen or Plunkr that demonstrates this issue.

ThomasBurleson avatar Dec 04 '15 10:12 ThomasBurleson

Ok give me a little time . i ll put up a plunker

jeson114 avatar Dec 04 '15 14:12 jeson114

ok while creating the demo i realised that my load functions for md-on-open and similarly the get functions for creating radio buttons were not asynchronous . So instead i used $q in those functions and it works now.

  vm.getLanguages = function () {
        var results = [];
        var deferred = $q.defer();
        masterService.meta('Languages').get().$promise.then(function (data)    {console.log("Languages", data);
            angular.forEach(data.value, function (value, key) {
                results.push({
                    Id: value.Id,
                    Name: value.Name
                });
            });
            deferred.resolve(results);
            console.log(results);
            return deferred.promise;
        });
        vm.languages = results;
        console.log("langs",vm.languages);
        return results;
    }

jeson114 avatar Dec 05 '15 06:12 jeson114

+1

mohsinmuzawar avatar Jan 23 '16 11:01 mohsinmuzawar

Still facing the same problem [$compile.ctreq] on close and reopen of a $mddialog ..

jeson114 avatar Jan 23 '16 11:01 jeson114

@jeson114 Are you able to create a Codepen demo that we can reproduce the error?

topherfangio avatar Feb 04 '16 22:02 topherfangio

I discovered an other solution described below.

First I placed the HTML of the fields that was throwing the exceptions of Angular inside a NG-REPEAT code, and in JavaScript code of Angular I did a push inside the list when the interface was ready to be built.

Below my HTML before the changes:

<div class="form-group" layout="row" flex>
<md-input-container layout="column" flex>
    <label>Field Name</label>
    <md-select ng-model="service.selectedChart.serieField">
        <md-option ng-repeat="column in columns" ng-value="column.columnName">
            {{column.columnName}}
        </md-option>
    </md-select>
</md-input-container>
</div>

HTML after changes:

<div ng-repeat="control in controls"><div class="form-group" layout="row" flex>
<md-input-container layout="column" flex>
    <label>Field Name</label>
    <md-select ng-model="service.selectedChart.serieField">
        <md-option ng-repeat="column in columns" ng-value="column.columnName">
            {{column.columnName}}
        </md-option>
    </md-select>
</md-input-container>
</div></div>

In JavaScript, before to fill the information in my models to present the options of my md-select I set my NG-REPEAT model with an empty Array, like this:

$scope.controls = [];

After all data got ready to be presented, I just append a new item in my array with this command.

$scope.controls = [{}];

I used this code in 3 places of my application and it worked fine. These fields was in forms placed inside $mdDialog.

claudiozanin avatar Mar 22 '16 21:03 claudiozanin

This error occurs when you use a mddialog with a template (containing for instance mdSelect-elements) attached. If this template has a directive linked the mdselect elements will drop this error if dialog is closed down and opened again. I can reproduce this without asynchronous calls, so that's not the problem. Unfortunately plnkr is currently down so I cannot provide an example.

Undrium avatar Mar 29 '16 10:03 Undrium

Created a plnkr, also realised this only occurs if you choose to send the scope with the mdDialog and preserve the scope.

http://plnkr.co/edit/8fgPvsNA5YDgKC9DDYKs

Just open up the dialog twice to reproduce the error.

Undrium avatar Mar 30 '16 08:03 Undrium

@Undrium we have same problem. Did you find any solution ?

huseyinalp-zz avatar Mar 30 '16 14:03 huseyinalp-zz

@huseyinalp You can probably get around this not using scope, however it would look really ugly if you are dependant of content from scope.

Undrium avatar Mar 31 '16 09:03 Undrium

@Undrium Thanks for the demo; can definitely see the error.

@EladBezalel Can you please take a look?

topherfangio avatar Apr 04 '16 17:04 topherfangio

Does someone have a workaround for this issue? I cannot afford to not preservescope, as my modal content is dependent on the parent view. Any help is much appreciated!

KalpanaAr avatar May 13 '16 23:05 KalpanaAr

+1

sookinoby avatar Jun 18 '16 04:06 sookinoby

+1

mmamane avatar Dec 09 '16 20:12 mmamane

@KalpanaAr, have you found any solution, i do have the same issue. please share if you got one

chaituGS avatar Dec 21 '16 05:12 chaituGS

+1

SinghB avatar Dec 28 '16 15:12 SinghB

This is a work around I used on facing the same issue - also similar to #6820

Earlier:

        $mdDialog.show({
            controller: filterDialogCtrl,
            controllerAs: 'ctrl',
            locals:{localVars: localVars},  // localVars is other data to pass to the dialog
            bindToController: true,
            templateUrl: './dialogModalPathHere.html',
            parent: angular.element(document.body),
            targetEvent: $event,
            clickOutsideToClose: true,
            scope: $scope,
            preserveScope: true,
        })

I passed $scope as a local var and removed scope and preserveScope params.

Changes after using workaround

        $mdDialog.show({
            controller: dialogCtrl,
            controllerAs: 'ctrl',
            locals:{parentScope: $scope, localVars: localVars},  // localVars is other data to pass to the dialog      
            bindToController: true,
            templateUrl: './dialogModalPathHere.html',
            parent: angular.element(document.body),
            targetEvent: $event,
            clickOutsideToClose: true,
        }) 

Now inside the dialogCtrl, I can access the parent scope as

parentScope.applyFilters(self.dataFromDialogHere);

vjku avatar Feb 02 '17 04:02 vjku

thanks @vjku this works for me

lmichailian avatar Feb 14 '17 20:02 lmichailian