Andrei Andrei - 1 month ago 15
Javascript Question

Ionic / Angular JS - How to parse {{value}} inside onclick

I have this Angular JS HTML:

<ion-view view-title="Articol">
<ion-content class="padding">
<img ng-src="{{article.image}}">
<h2>{{article.title}}</h2>
<p>{{article.published}}</p>
<p ng-bind-html="article.text"></p>
<p>
<button onclick="window.plugins.socialsharing.shareViaFacebook(null /* msg */, null /* img */, '{{article.url}}')">Facebook</button>
<button onclick="window.plugins.socialsharing.shareViaTwitter(null /* msg */, null /* img */, '{{article.url}}')">Twitter</button>
</p>
</ion-content>
</ion-view>


Everything is working fine but not the
{{article.url}}
inside
onclick=""
. If I put the
{{article.url}}
inside a
<p></p>
it's working fine. How can I fix this?

Answer

whyyie's answer could be fine, however, other way, if you want to keep it fully clean (i.e no script in html), it can achieved as

<button ng-click="posttofb()">Facebook</button>

In controller

app.controller(funcion($scope){    

$scope.posttofb = function (){    
window.plugins.socialsharing.shareViaFacebook(null, null, $scope.article.url);
}

});