0

i have an asp web API project and related AngularJS project.
i know if i want to give appearance to Angular, i should call index.html so

  1. how can i call index.html file of Angular as default page?
  2. best place to import Angular folders in ASP web API project?

RouteConfig:

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

art of WebApiConfig:

config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
1
  • @Tui Popenoe... no .evrything work fine in my angular project, i just want to know how to run index.html of angular project when localhost:6993/ called. Commented Mar 4, 2015 at 16:06

1 Answer 1

1

If you want to use angularjs routing setup your routeConfig like this:

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "App",
            url: "App/{*catchall}",
            defaults: new { controller = "App", action = "Index" });

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "App", action = "Index", id = UrlParameter.Optional }
        );

In your index.cshtml view you will need to define your app on the HTML tag like so and add your ng-view directive:

<html ng-app="appModule">
   <div ng-view>
   </div>
</html>

This will get the app going. Make sure include all your .js files in your index.cshtml files.

In the app (mvc) controller we bootstrap some data in for the angular app. You can do this however you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.