Andrei Andrei - 1 year ago 134
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}}">
<p ng-bind-html="article.text"></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>

Everything is working fine but not the
. If I put the
inside a
it's working fine. How can I fix this?

Answer Source

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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download