Can't call function


#1

I’m putting together a ionicPopup and within your content, I need to make a call to a function. The problem is that not called me and read as undefined function. I leave my code.

$scope.verInfo = function(marker,marker){
$ionicPopup.show({
   title: 'Información View',
   subTitle: '',
   content: '<i class="'+marker.icono+' ver_view-1" id="icono_like" ng-cloak ng-click='+$scope.darLike(marker.id)+'><span>'+marker.like+'</span></i>',
   buttons: [
    { text: 'Salir',
            onTap: function(e){
              
            }
    },
     {
       text: 'Ver Detalle',
       type: 'button-positive',
       onTap: function(e) {
          $scope.verView(marker.id);
       }
     },
   ]
  })
}

It’s a bit messy because the content is pure html. but $ scope.darLike function is not working, is not declared when inspecting items within the popup.


#2

Try ng-click='darLike(marker.id)' instead.


#3

Still not working …

That’s what you get :

<i class="icon ion-android-favorite-outline ver_view-1" id="icono_like" ng-click="undefined"><span>2</span></i>

#4

If the function is called $scope.darLike you need ng-click to have darLike as a string in the ng-click, but marker.id needs to be taken from the javascript, so something like this:

ng-click="darLike(' + marker.id + ')"

and you need to pass scope to the popup

$ionicPopup.show({
    title: 'Información View',
    subTitle: '',
    content: contentHtml,
    scope: $scope,
    ...

Codepen example: http://codepen.io/brandyshea/pen/NqqgMW?editors=101


#5

:blush: thank you! it works great for me!