5

I have a code,that shows a modal with this code using jquery:

$('#myModal').modal({'show':true});

but with angular.js not works. what is the equivalent of $('#myModal') using angular.js?

// not works for me
angular.element("#myModal")
yavg
  • 2,761
  • 7
  • 45
  • 115
  • can you `console.log(angular.element("#myModal"))` – brk Feb 26 '18 at 04:11
  • Don't do it this way; Manipulating the DOM should only be a last resort when you can't get AngularJs to do what you want any other way (extremely rare). In case of a modal, an `ng-show` should be all you need. – Claies Feb 26 '18 at 04:23
  • You need to use angular bootstrap directive https://aashishkoirala.wordpress.com/2014/03/17/angular-bootstrap-modal/ – Sudharsan S Feb 26 '18 at 04:47
  • Possible duplicate of [angular.element vs document.getElementById or jQuery selector with spin (busy) control](https://stackoverflow.com/questions/17230242/angular-element-vs-document-getelementbyid-or-jquery-selector-with-spin-busy-c) – Rakesh Burbure Feb 26 '18 at 06:32

2 Answers2

4

You can use document.querySelector to get the dom element and then use angular.element

var elem = angular.element(document.querySelector('#myModal'));
Vineesh
  • 3,762
  • 20
  • 37
0

You can also try by injecting $document

var elem = $document('#myModal');

In your case, you also do this little change to make your program run.

var elem = angular.element(document).find('#myModal');
Rakesh Burbure
  • 1,045
  • 12
  • 27