1

I have an assignment to implement a preview of an URL which means it will display the logo and tagline just like facebook.

I know that we have urLive library in jQuery but i have to implement in angularjs.I have tried following code but it doesn't work.

<body ng-app="myapp">
        <div ng-controller="AppCtrl">
        <iframe ng-src="{{currentUrl}}"> </iframe>
        </div>

        <script>
            var app=angular.module('myapp',[]);
                app.controller('AppCtrl',function($scope,$sce){
                $scope.currentUrl = $sce.trustAsResourceUrl("http://facebook.com");
            }); 
       </script>

Do we have any such thing in angularjs?`

Pogrindis
  • 7,755
  • 5
  • 31
  • 44
rahul
  • 383
  • 1
  • 8
  • 20

1 Answers1

0

You missing couple of things

  1. Add missing Angular sanitize reference

  2. Inject 'ngSanitize' module inside you add

CODE

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular-sanitize.min.js"></script>


   <script>
        angular.module('myapp', ['ngSanitize'])
            app.controller('AppCtrl',function($scope,$sce){
            $scope.currentUrl = $sce.trustAsResourceUrl("http://facebook.com");
        }); 
   </script>

Working Fiddle

You can also do it by making it angular filter like this

NOTE

You can not load http://www.facebook.com inside iframe refer this SO Question for more information.

Hope this could help you. Thanks

Community
  • 1
  • 1
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
  • can you give the code how you added angular references? Thats last thing i can take a look – Pankaj Parkar Feb 04 '15 at 19:34
  • – rahul Feb 04 '15 at 19:38
  • 1
    Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/70257/discussion-on-answer-by-pankajparkar-url-preview-with-tagline-and-logo-in-angula). – Taryn Feb 04 '15 at 19:49
  • 1
    @pankajparkar Since I moved the comments to chat, they should be able to join. – Taryn Feb 04 '15 at 19:54