Ionic / Angular JS - 如何在onclick

时间:2016-10-31 13:50:30

标签: javascript angularjs ionic-framework

我有这个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>

一切正常,但不是{{article.url}} onclick=""。如果我将{{article.url}}放在<p></p>内,它可以正常工作。 我该如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

更好的方法是保持它完全清洁(即html中没有脚本),它可以实现

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

在控制器中

app.controller(funcion($scope){    

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

});

答案 1 :(得分:0)

<button onclick="window.plugins.socialsharing.shareViaFacebook(null /* msg */, null /* img */, {{article.url}})">Facebook</button>

中删除单引号
#include <stdio.h>
#include <stdbool.h>

typedef struct Re{
int x,y;
char a;
}Re;


void initRe(Re *r,int a,int b, char x){

r->x = a;
r->y = b;
r->a = x;

}

void showRe(Re *r,int a,int b, char x){

printf("%d %d %c \n",(*r).x,(*r).y,(*r).a);

}


bool compareAforEqualityChar(void *a,void *b){
//printf("%c    %c \n",*(char*)a,*(char*)b);
if(*(char*)a==*(char*)b){return true;}
return false;
}

bool compareAforEqualityInt(void *a,void *b){
//printf("%d    %d \n",*(int*)a,*(int*)b);
if(*(int*)a==*(int*)b){return true;}
return false;
}

int searchAddressed(void * start , int elesize ,void *x , bool compare(void *, void *)){

    char *ptr =(char *)start; //Use char since one byte

    int i;
    for (i=0; i<10;i++){    
        if (compare((ptr+i*elesize),x)){  //call compare function
          printf("%d",i); // index where match is found
        }

      }

}

int main(void){
    Re r[10];

    int x=0;
    int y=0;
    char a ='A';

    for(int i=0;i<10;i++){
        initRe(&r[i],x,y,a); //Initialise Struct with some values
        x++;
        y++;
        a++;
    }


    for(int i=0;i<10;i++){
       showRe(&r[i],x,y,a); // Show All values
    }

    int elesize = sizeof(r[0]);

    int z = 'C';
    searchAddressed(&r[0].a,elesize,&z,compareAforEqualityChar);

//searchaddressed(struct member pointer, struct size, pointer of variable to check, pointer function to chechkwith)
   }