我希望在AngularJS中发送一个“URL”作为参数。
===
成功:
example.com/purchase/loremipsum
失败(否则重定向):
example.com/purchase/http%3A%2F%2Fwww.google.com
==
javascript
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/gallery', {
templateUrl: 'partials/gallery.html',
controller: 'galleryCtrl'
}).
when('/purchase/:url', {
templateUrl: 'partials/purchase.html',
controller: 'PurchaseCtrl'
});
}]);
app.controller('GalleryCtrl',function ($scope, $http, $rootScope, $routeParams, $modal, $log, $location){
$http.get(url).
success(function(data){
$scope.itemUrl = encodeURIComponent(data.url);
});
});
app.controller('PurchaseCtrl',function ($scope, $http, $rootScope, $routeParams, $modal, $log, $location){
$scope.url = $routeParams.url;
alert($scope.log);
});
gallery.html
<a ng-href="#/purchase/{{itemUrl}}">BUY</a></div>
答案 0 :(得分:0)
%2F将转换为'/'
这意味着angular将尝试找到example.com /purchase / http://www.google.com的匹配项,这与您的模式'/ purchase /:url'不匹配