Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

$mdDialog bug using template vs. templateURL #3191

Closed
nikkwong opened this issue Jun 9, 2015 · 5 comments
Closed

$mdDialog bug using template vs. templateURL #3191

nikkwong opened this issue Jun 9, 2015 · 5 comments
Assignees
Milestone

Comments

@nikkwong
Copy link

nikkwong commented Jun 9, 2015

I have two, almost identical scripts calling a mdDialog via mdDialog.show. One of which, uses an inline template, the other, which references a templateUrl. The one that uses the inline template, throws a i.hasAttribute is not a function error—while the other one works just fine.

Not working (inline template)

http://plnkr.co/edit/m6HDhrgcVlXumwDhyQYu?p=preview

Working (templateUrl)

http://plnkr.co/edit/955VxMkBjPy5DvmQjIg0?p=preview

Known bug?

Just to note—this bug isn't plnkr specific, it's happening to me locally as well. Thanks!

@ThomasBurleson ThomasBurleson self-assigned this Jul 6, 2015
@ThomasBurleson ThomasBurleson modified the milestone: Backlog Jul 6, 2015
@GuyShaanan
Copy link

+1
Also having the same problem with $mdDIalog and templateUrl:
The following lines (22-26) from material/src/core/services/aria/aria.js in tag 0.10.1 might shed some light:

function expect(element, attrName, defaultValue) {
    var node = element[0] || element;

    // if node exists and neither it nor its children have the attribute
    if (node &&
       ((!node.hasAttribute(attrName) ||
        node.getAttribute(attrName).length === 0) &&
        !childHasAttribute(node, attrName))) {

In my case, element is an empty array ([]), so after

 var node = element[0] || element;

node is an empty array itself, and the expression if(node), where node is an empty array, evaluates to true.

(This doesn't fix the issue, just explains why the exception is thrown)

@smashercosmo
Copy link

Just faced the same issue. Dialogs with inlined templates simply don't open, because of js error.
@ThomasBurleson why it's in the backlog? Seems pretty critical to me.

@ThomasBurleson
Copy link
Contributor

@GuyShaanan - your comment is helpful.
@smashercosmo - some items are in the backlog because the team is simply working at maximum capacity with other issues. Nevertheless, with the above information, I think this can be quickly resolved.

@ThomasBurleson ThomasBurleson modified the milestones: 0.12.0, Backlog Aug 27, 2015
kennethcachia pushed a commit to kennethcachia/material that referenced this issue Sep 23, 2015
Using $mdDialog to show html content without a mdDialog parent node will throw an error:
```js
$mdDialog.show({
  targetEvent: ev,
  controller : DialogCtrl,
  parent     : angular.element(document.body),
  template   : '<div ng-click="answer(\'string\')">click here</div>'
}
```

If a mdDialog template does not contain a wrapper `md-dialog` node, then auto-wrap.
If a `$mdUtil.extractElementByName` does not find the target element, warn the user.

Fixes angular#3191. Fixes angular#4206.
@jessekoconnor
Copy link

Is the resolution here that you just cannot use a templateUrl?

@Splaktar Splaktar modified the milestones: 1.0-rc1, 0.11.0 Apr 10, 2019
@Splaktar
Copy link
Member

@jessekoconnor no, this was fixed in 22c34ba as part of 0.11.0. Please take a look at the restrictions section of this doc: https://material.angularjs.org/latest/api/service/$mdDialog.

@angular angular locked as resolved and limited conversation to collaborators Apr 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants