开发者社区> 问答> 正文

如何在angularjs和PHP之间添加routeparams

我已经在angular js和PHP文件中成功添加了路由参数。但是我需要为一个文件添加URL参数。我加了。但是它显示了一个错误。

我附上下面的代码

var mainbread = angular.module('mainbread', ['ngSanitize', 'ui-notification','ngRoute', 'ngStorage', 'angular.filter', 'moment-picker', 'ngMaterial', '720kb.socialshare']) mainbread.config(function (NotificationProvider, $routeProvider, $locationProvider) { NotificationProvider.setOptions({ delay: 5000, startTop: 40, startRight: 40, verticalSpacing: 20, horizontalSpacing: 20, positionX: 'right', positionY: 'top' }),
$routeProvider .when("/", { templateUrl : "/home.php", controller: "maincontrol" }) .when("/donate", { templateUrl : "/donate.php", controller: "maincontrol" }) .when("/donate/:raiser", { templateUrl : "/donate.php", controller: "donatectrl" }) .when("/about", { templateUrl : "/about.php", controller: "maincontrol"
}) .when("/blog", { templateUrl : "/blog.php", controller: "maincontrol"
}) .when("/contact", { templateUrl : "/contact.php", controller: "maincontrol" }) .when("/terms", { templateUrl : "/terms.php", controller: "maincontrol" }) .when("/policy", { templateUrl : "/policy.php", controller: "maincontrol" }); $locationProvider.html5Mode(true); }); // 'use strict'; mainbread.controller('maincontrol', ['$scope', '$filter', '$http', 'Notification', '$compile', '$window', '$rootScope', '$location', '$mdDialog', function ($scope, $filter, $http, Notification, $compile, $window, $rootScope, $location, $mdDialog) { }]);

mainbread.controller('donatectrl', ['$scope', '$filter', '$http', 'Notification', '$compile', '$window', '$rootScope', '$location', '$mdDialog','$routeParams',
function ($scope, $filter, $http, Notification, $compile, $window, $rootScope, $location, $mdDialog,$routeParams) {
    $scope.raiser = $routeParams.raiser;
    alert("$scope.raiser");
}]);

在上面的代码中,我添加了路由参数“ raiser ”。当我在URL中使用某些参数(例如domain / donate / myid)时,URL 会将donate视为目录。所以错误显示如下 错误

我也为此写.htaccess。随附以下代码。这有什么问题吗?

RewriteEngine On Options FollowSymLinks

RewriteBase /

DirectoryIndex main.html

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /#/$1 [L] 我该如何解决?

展开
收起
社区秘书 2019-12-04 13:50:16 610 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载