0

I am trying to implement the angular dynamic $routeProvider based on importing json values. here i'm unable to get correct syntax can any one help to solve This. my issue is here i'm trying make $routeProvider as dynamic by avoiding the hard code but unable to send params to tempateUrl var url="/demo1/:type", config = { templateUrl: function (params) { return "/"+route.routePathAction } } , $routeProvider.when(url,config);

$routeProvider.when('/demo1/:type', { templateUrl: function (params) { return '/demo/demo1?type=' + params.type; } })

here

my _layout.cshtml

<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <meta charset="utf-8" />

    <title>@ViewBag.Title</title>
    <!-- These will be in all pages -->
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/angular")

    <!-- These scripts will be from thew "Scripts" view -->
    @RenderSection("scripts", required: false)

    <!-- These styles will be in all pages -->
    <link href="~/Content/menu.css" rel="stylesheet" />
    <script src="~/Scripts/myapp.js"></script>  
    @Styles.Render("~/Content/css")
</head>

<body> 
        <h2>Index</h2>
           <ul>
            <li><a href="#/demo">Test link number "demo/:type" </a></li>
            <li><a href="#/demo1/122222234/hello">Test link number "demo/:type/:type" </a></li>
            <li><a href="#/demo2/12321323">Test link 1 number "demo/:type" </a></li>
           </ul>
        <div ng-view> </div>
    </div>

    @RenderBody()

</body>
</html>

myapp.js file :

var app = angular.module('myApp', ['angular.filter', 'ngRoute']);
  app.config(["$routeProvider", function ($routeProvider) {
        var setRoutes;
        var routes = [{ routePath: "demo", routePathAction: "demo/demo3" },
                      { routePath: "demo1/:type", routePathAction: "demo/demo1?type=' + params.type;" },
                      { routePath: "demo2/:type1/:type2", routePathAction: "demo/demo4?type1=' + params.type1 + '&type2=' + params.type2;" }];
            setRoutes = function (route) {
                       var config, url;
                       return url = "/" + route.routePath, config = { templateUrl: function (params) { return "/" + route.routePathAction } },                      
                       $routeProvider.when(url, config).otherwise({ redirectTo: "/" });
               }
        routes.forEach(function (route) {
                return setRoutes(route)
             })

         }]);  

i'm trying implement the below content as dynamic

var app = angular.module('myApp', ['angular.filter', 'ngRoute']);
    app.config(["$routeProvider", function ($routeProvider) {
 $routeProvider.when('/demo', {
                        templateUrl: function (params) { return '/demo/demo3' }
                    })
                    .when('/demo1/:type', {
                        templateUrl: function (params) { return '/demo/demo1?type=' + params.type; }
                     })
                      .when('/demo1/:type1/:type2', {
                          templateUrl: function (params) { return '/demo/demo4?type1=' + params.type1 + '&type2=' + params.type2; }
                    }).otherwise({ redirectTo: "/" })
  • what is the specific problem? Note you only need one `otherwise` – charlietfl Oct 26 '15 at 12:00
  • here i need to pass some params but i'm unable to send those params because of some syntax here i need like this ` templateUrl: function (params) { return '/demo/demo1?type=' + params.type; }` myjson strucure is `{ routePath: "demo1/:type", routePathAction: "demo/demo1?type1=' + params.type"}` , here the problem is routePathAction structure. how pass params value in json string structre ? – Brahmaiah P Oct 27 '15 at 05:22

0 Answers0