angularjs - How to launch url in a modal? -


i trying launch modal has url in when user clicks button.

i have these:

mymodal.html:  <div class="modal-header">     title 1 </div> <div class="modal-body">   <iframe id="iframe" ng-src="{{my_url}}"> </div>  in js:  $scope.clickbutton = function(){     var modal = $uibmodal.open({         templateurl: 'mymodal.html'         controller: 'myctrl',              }); })  in myctrl:    ....   $scope.my_url = 'http://myotherproject/project/index.html';   .... 

i want url launched modal shows. iframe approach works wondering if there more elegant way this. help!

depending on trying achieve here, if want display html own styles, can use $sce.trustashtml , ng-bind-html directive. if want custom styles inside , js, iframe safer solution.

angular.module('app', []);    angular    .module('app')    .controller('example', function ($sce) {      const somehtml = `        <strong>blah</strong><br>        <hr>        <h1>blah</h1>      `;          this.somehtml = $sce.trustashtml(somehtml);    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>  <div ng-app="app" ng-controller="example example">    <div ng-bind-html="example.somehtml"></div>  </div>

you can inject html , compile it. if want html behave regular angular template.

angular.module('app', []);    angular.module('app').directive('compile', ($compile) => {    return {      restrict: 'a',      link: (scope, element, attrs) => {        attrs.$observe('compile', (html) => {          const content = $compile(html)(scope);                    element.empty();          element.append(content);        });      }    };  });    angular.module('app').controller('example', function () {    this.x = 0;    this.somehtml = `      <div>        {{example.x}}<br>        <button type="button" ng-click="example.x = example.x + 1">+1</button>      </div>    `;  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>  <div ng-app="app" ng-controller="example example">    <div compile="{{example.somehtml}}"></div>  </div>

in example skipped fetching part, assume know how use $http.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -