启用ng-click以在浏览器窗口中打开链接

时间:2016-06-12 11:37:50

标签: javascript angularjs angularjs-ng-click

我点击了我的数据生成了一个有效的网址,但很难在浏览器窗口中打开,因为这会触发我的第三方应用程序打开。

我已经尝试了一些选项,并在Stack和Google上找到了一些额外的按钮选项(2-6),任何人都可以帮助它在浏览器中打开吗?

这是一个应用程序的图像,显​​示当我点击全宽按钮和Plunker中的代码时控制台输出。

http://i.imgur.com/0tfxTuE.jpg

https://plnkr.co/edit/WBYfa3m19MAwobtdbdfU

    // Ionic Starter App

    // angular.module is a global place for creating, registering and retrieving Angular modules
    // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
    // the 2nd parameter is an array of 'requires'
    angular.module('starter', ['ionic','ngCordova'])

    .run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {



        if(window.cordova && window.cordova.plugins.Keyboard) {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

        // Don't remove this line unless you know what you are doing. It stops the viewport
        // from snapping when text inputs are focused. Ionic handles this internally for
        // a much nicer keyboard experience.
        cordova.plugins.Keyboard.disableScroll(true);
        }
        if(window.StatusBar) {
        StatusBar.styleDefault();
        }
    });
    })

    .config(function($stateProvider, $urlRouterProvider) {

    $stateProvider
        .state('tabs', {
        url: '/tab',
        abstract: true,
        templateUrl: 'templates/tabs.html'
        })
        .state('tabs.home', {
        url: '/home',
        views: {
            'home-tab' : {
            templateUrl: 'templates/home.html'
            }
        }
        })
        .state('tabs.list', {
        url: '/list',
        views: {
            'list-tab' : {
            templateUrl: 'templates/list.html',
            controller: 'ListController'
            }
        }
        })
        .state('tabs.detail', {
        url: '/list/:aId',
        views: {
            'list-tab' : {
            templateUrl: 'templates/detail.html',
            controller: 'ListController'
            }
        }
        })

        // if none of the above states are matched, use this as the fallback
        $urlRouterProvider.otherwise('/tab/home');

    })

    .controller('ListController', ['$scope', '$http', '$state','$cordovaBluetoothSerial', '$location', function($scope, $http, $state, $cordovaBluetoothSerial, $location) {
            $http.get('js/aboDATAONLY.json').success(function(data) {
            $scope.orders = data;
            $scope.whichorder = $state.params.aId;
            })

            function onPay() {
            var itemsArr = [];
            var invoice = {};
            var myItems = {};
            var myItem = {};

            myItem['name'] = "Sphero";
            myItem['description'] = "A robotic ball that can be controlled via apps";
            myItem['quantity'] = "1.0";
            myItem['unitPrice'] = "129.00";
            myItem['taxRate'] = '0.0';
            myItem['taxName'] = 'Tax';
            itemsArr.push(myItem);
            myItems['item'] = itemsArr;

            invoice['itemList'] = myItems;
            invoice['paymentTerms'] = 'DueOnReceipt';
            invoice['currencyCode'] = 'GBP';
            invoice['discountPercent'] = '0';
            invoice['merchantEmail'] = 'myemail@mail.com';
            invoice['payerEmail'] = 'foo@bar.com';

            var returnUrl = 'http://wp1175175.wp220.webpack.hosteurope.de/speedhack/index.html';
            var retUrl = encodeURIComponent(returnUrl + "?{result}?Type={Type}&InvoiceId={InvoiceId}&Tip={Tip}&Email={Email}&TxId={TxId}");
            var pphereUrl = "paypalhere://takePayment/v2?returnUrl=" + retUrl;
            //var pphereUrl = "paypalhere://takePayment/?";
            pphereUrl = pphereUrl + "&accepted=cash,card,paypal";
            pphereUrl = pphereUrl + "&step=choosePayment";
            pphereUrl = pphereUrl + '&invoice=' + escape(JSON.stringify(invoice));
            console.log(pphereUrl);

            return pphereUrl; 
        }

        $scope.pay = function () {  
            window.location = onPay();
        };

    }]);

1 个答案:

答案 0 :(得分:0)

尝试

var url = onPay();
    window.open(url , '_blank');