离子:分割<a> tag window.open url to include data

时间:2017-09-12 12:39:06

标签: javascript html url ionic-framework window.open

I am trying to split up a URL in my tag.

Inside one of my templates.html files in Ionic, I am linking externally to Twitter and Facebook.

I am using Cordova InAppBrowser and to cut a long story short, the links for Twitter and Facebook open in the correct apps/system browsers... but I cannot figure out a way to include data of which I can use in a simple version.

When using:

<a class="twitter" onClick="window.open('https://twitter.com/intent/tweet?text={{offer.title}}%20-%20{{offer.business.data.name}}%20-%20via%20@handle','_system','location=yes');return false;"><i>&#xE12f;</i> Twitter</a>

It opens correctly, but does not inherit the correct data for {{offer.title}} and {{offer.business.data.name}} - I need a way for it to include this.

When using:

<a class="twitter" href="https://twitter.com/intent/tweet?text={{offer.title}}%20-%20{{offer.business.data.name}}%20-%20via%20@handle" target="_system"><i>&#xE12f;</i> Twitter</a>

It loads the correct data into the URL, but does not open correctly at all which is more of an issue - there must be a way to do a simple:

'url.com/' + {{offer.title}} + '/something'

or something?

1 个答案:

答案 0 :(得分:0)

有很多方法可以实现这一点,但在Angular.js中处理此问题的最有效方法是使用ng-click。如下所示:

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';

  $scope.offer = {
    title: 'someTitle',
    business: {
      data: {
        name: 'some Business'
      }
    }
  };

  $scope.openTwitter = function(offer) {
    window.open('https://twitter.com/intent/tweet?text=' +
      offer.title +
      '%20-%20' +
      offer.business.data.name +
      '%20-%20via%20@handle', '_system', 'location=yes');
  }
});

HTML:

<a ng-click="openTwitter(offer)" href="">Open Twitter</a>

http://plnkr.co/edit/tqQWHc0nlp9Rpo85aSbV