【发布时间】:2016-12-06 03:18:16
【问题描述】:
我在 li 标签中动态获取“站点名称”,点击后我想在 iframe 中打开“链接”。
我在响应中得到的以下 json 格式数据
响应数据:
[{ "SrNo":1, "id":1, "sitename":"Tutorial Poin", "link":"http://www.tutorialspoint.com", }, { "SrNo":2, "id":6, "sitename":"W3Schools", "link":"http://www.w3schools.com", },]
HTML Code::
<tr> <td style="width: 11%; vertical-align: top;"> <ul id="ultabs" ng-model="ultabs"> <li ng-repeat="site in sites"> <a href="#frameDiv" ng-click="navigate(site.link)">{{site.sitename}}</a> </li> </ul> </td> <td style="width: 80%; vertical-align: top; text-align: left;"> <div id="frameDiv" style="margin-top: 5px;"> <iframe id="Iframe" ng-model="Iframe" ng-src="{{myLink}}"></iframe> </div> </td></tr>
Conroller code::
var app = angular.module('myApp', []); //app.filter('trustAsResourceUrl', ['$sce', function ($sce) { // return function (val) { // return $sce.trustAsResourceUrl(val); // }; //}]) app.controller('formCtrl', function ($scope, $http) { (function init() { $http({ method: 'POST', url: "../Ajax/Ajax_Mastermanagement_StudyLinks", params: { mode: 'getData' } }).then(function mySucces(response) { $scope.sites = response.data; $scope.myLink = response.data[0].link; }, function myError(response) { $scope.message = response.statusText; }); })(); $scope.navigate = function (link) { /* $('#Iframe').attr("src",link);<==This codeworking well,But i want to set "ng-src" attribute in iframe using AngularJs.*/ } });
为了在 iframe 中获取 ng-src,我也尝试了过滤器,但是当我添加过滤器的代码时,我什至无法获得响应数据。
提前谢谢你
【问题讨论】:
-
能否请您创建一个小提琴或 plunker 来重现该问题。通过查看它应该可以工作的代码!