0

I'm trying to display webview using angularjs and make the webview url stocken in a list of webviews : webview.url. The problem is when a person start navigate in the webview, the url change in the webview (src attribute) but not in the webvew.url in the list of items. To understand this issue I made this example with Iframe : http://plnkr.co/edit/MTgNNNZefliS507Fw0Jj?p=preview

How can I make the src value changing in the webview modifie automatically the webview.url in my list of items ? I mean make ng-src 2-way-binding.

Thanks!

In my page:

  <ul id="myviews" class="cd-nav">
        <li id="{{webView.id}}" ng-repeat="webView in webViews">
           <webview id="webview{{webView.id}}" class="mywebviews" ng-src="{{webView.url}}">
           </webview>
        </li>
     </ul> 

In my app.js :

 var trustedUrl = $scope.trustSrc("http://google.com");
        $scope.webViews = [
            {
                id : "webview0",
                url: trustedUrl,
                classe: "opened"
            }
       ];

When a client try to visit an url:

   var idnewwebview = $scope.webViews.length + 1;
        var trustedUrl =.// Recupered via an input...
        $scope.webViews.push(
                        {
                            id : idnewwebview,
                            url: trustedUrl,
                            classe: "opened"
                        }
                     );
Kacem
  • 79
  • 7
  • 1
    Did you try `ng-src="{{webView.url}}"`? – Michael Oct 12 '15 at 14:28
  • Yes already. The problem is thet client navigation doesn't update the webview.url item in $scope.webviews .. So when I try to get back the webview, it reurn the webview with the initial url :( – Kacem Oct 13 '15 at 09:19
  • Then you have a bug in your code. Please provide a working plunker for further support. – Michael Oct 13 '15 at 09:26
  • My code is correcte. I made this plunker example with iframe because webviews don't work on web pages. http://plnkr.co/edit/MTgNNNZefliS507Fw0Jj?p=preview In this example you can navigate in the iframe, but after click in new iframe buttom, you lose your navigation. – Kacem Oct 13 '15 at 13:33
  • Ok, I understood the problem now. ng-src is not a 2-way-binding. You can define a `$scope.$watch` on the `angular.element('iframeId').contents().get(0).location.href )`. See http://stackoverflow.com/questions/748727/getting-the-current-src-of-an-iframe-using-jquery. But this will only work if the iframe contains the same domain. Cross domain access if forbidden by security. But maybe it might work with `webview` elements. – Michael Oct 13 '15 at 16:14
  • It cannot resolve my problem :( – Kacem Oct 21 '15 at 13:39

0 Answers0