如何在angularjs和PHP之间添加routeparams

问题描述 投票:0回答:1

我已成功在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视为目录。所以错误显示如下Error

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

RewriteEngine On 
Options FollowSymLinks

RewriteBase /

DirectoryIndex main.html

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]

我该如何解决?在此提供帮助

javascript php angularjs routing routeparams
1个回答
0
投票

我完全理解。一个PHP页面将首先运行。然后只有角度js。因此,在这种情况下,我们无法从angular js到PHP获取值。取而代之的是,我使用了API。现在问题解决了

© www.soinside.com 2019 - 2024. All rights reserved.