0

I am having trouble finding a tutorial using asp net core with Angular 1 without using Razor. (I just want to use html) int the web project with a web api solution that will get the requests.

I have been trying to make it work but for some reason i can't get the UI router to work:

like if i do http://localhost:12112/index.html it would show the page correcty but when i do `http://localhost:12112/home which is what i want.. it says it can't find it.

My folder structure is:

wwwroot
  -app
     -home
        -myhome.controller.js
        -myhome.module.js
        -myhome.router.js
        -myhome.html
  -index.html

myhome.router.js

(function () {
    'use strict';

    angular
        .module('hoa.myhome')
        .config(routeConfig);

    routeConfig.$inject = ['$stateProvider', '$urlRouterProvider']

    function routeConfig($stateProvider, $urlRouterProvider) {

        $urlRouterProvider.otherwise('/');
        $stateProvider

        .state('home', {
            url: '/',
            templateUrl: '/app/home/myhome.html'),
            controller: 'myHomeController',
            controllerAs: 'myhctrl'
        })
    };

})();

what could i be missing?, or if you could point me to a good tutorial using angular without razor and .net core i would appreciate it.

3
  • You haven't defined a route for home. Your home page is '/'. Are you using IIS? If so you can change your default document to index.html that way you won't have to specify it in the browser. Commented Sep 27, 2016 at 19:50
  • but i do not want to show /index.html in the url, i want it to be localhost , then if i do /home it will bring in the home partial. Yeah it's IIS Commented Sep 27, 2016 at 19:52
  • I've created a tutorial using asp.net core and angularjs. There I use a HomeController to serve the index page (it's easier), but you can create a index.html in your wwwroot folder. Commented Sep 27, 2016 at 20:34

2 Answers 2

1

If what you want is plain html and javascript for an SPA that will handle routes by itself like angular, then you can instead of adding a new Project to the solution add a new Empty web site that will be plain html and javascript files.

Things to consider:
1. It will run on a different port/domain so you will have to configure CORS for the web api
2. You will not have any render side functionality available, everythin will be client side
3. Normally visual studio attacth the website to the solution, but place it on differente locations "users/documents/VSVersion/WebSites/" if you dont want that make sure to place it where you want it when you created it

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

Comments

0

To open the first index.cshtml page, you need to use an action on your Home controller

public IActionResult Index(){
    return View();
}

This will open the site. Then, in your index.cshtml:

div ng-app="myApp">
        <ui-view></ui-view>
</div>

your <ui-view></ui-view> can be populated with your angular html files and the url can be set and changed with your ui-router

2 Comments

I am not using razor (i do not want) i just want plain html - is this possible?. I am just going to make calls to an api that will return my model in json to my angular controller
If you don't add a HomeController to serve your "/" URL, then, you need to access localhost/index.html#!/home

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.