radio-button, select: throw error on $mddialog.show() and cancel()
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
There is no problem when i downgrade to 0.11.3
Please provide a CodePen or Plunkr that demonstrates this issue.
Ok give me a little time . i ll put up a plunker
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;
}
+1
Still facing the same problem [$compile.ctreq] on close and reopen of a $mddialog ..
@jeson114 Are you able to create a Codepen demo that we can reproduce the error?
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.
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.
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 we have same problem. Did you find any solution ?
@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 Thanks for the demo; can definitely see the error.
@EladBezalel Can you please take a look?
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!
+1
+1
@KalpanaAr, have you found any solution, i do have the same issue. please share if you got one
+1
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);
thanks @vjku this works for me