Search code examples
ionic-frameworkionic-view

How to write a $state parameter into an view (ionic)


I have this scenario an user clicks on a link, I catch the event and prevent it from redirect me to this url, instead I save it and send the user to an specific state/view using $state.go('app.myState', {myParam: url_captured});

The parameter gets sended but now I need to show this url inside an iframe in the view, I tried

<iframe src="{{$state.params.myParam}}"></iframe>

but it doesn't show anything just throw an empty iframe.

How to I access the parameter?


Solution

  • if you use this:

    src="{{$state.params.myParam}}"
    

    involve that in the scope of this controller there's a var named $state

    add this to your controller:

    $scope.myParam = $state.params.myParam
    

    then replace the iframe with:

    <iframe src="{{myParam}}"></iframe>