0

I want help in AngularJs routing with MVC6 .cshtml views I create normal _layout for that's contains the application pattern. And I reader Index.csthml to _layout using ReanderBody function. Now I'm trying to add 'div' ng-view to render all other .csthml views using angularjs inside the Index.csthml but my code it's did not work.

AngularJs script that's I use as following:

angular.module('myApp', [])
  .controller("MyController", function ($scope) {
      $scope.message = "My Message Is Super Awesome";
  });

angular.config(['$routeProvider',
  function ($routeProvider) {
      $routeProvider.
        when('/route1', {
            templateUrl: 'Home/BusinessLookup',
            controller: 'BusinessLookupController'
        }).
        otherwise({
            redirectTo: '/'
        });
  }]);

angular.controller('BusinessLookupController', function ($scope) {

    $scope.message = 'This is Add new order screen';

});

And Index.csthml file look like:

<div>
<a href="Home#/route1">Test</a>
<div ng-app="myApp" ng-controller="MyController">
    {{message}} <!--Here angular does not work-->

    <div ng-view=""></div>

</div>

MVC routing setup:

            app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}"
                );
        }
4
  • remove Home from this '<a href="Home#/route1">Test</a>' and try again please Commented Oct 12, 2015 at 11:16
  • also, if possible then can you please post the error log from DEVELOPER TOOL of you browser? Commented Oct 12, 2015 at 11:26
  • for getting start you can even go with this link codeproject.com/Articles/806029/… Commented Oct 12, 2015 at 11:27
  • DEVELOPER TOOL giving me error 'Uncaught TypeError: angular.config is not a function' Commented Oct 12, 2015 at 15:36

1 Answer 1

1

You need to create an instance of an angular module for your app:

var app = angular.module('myApp', []);

and then use it like this:

app.controller(...

app.config(...

Hope this helps.

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.