1

I have search a lot for finding problem in my code but didn't get solution. I'm trying routing in html file there are two links 1 for view1 and second for view2 code for both views are in different files in folder named parts and in js file i have created a module named mymodule my problem is when i remove "mymodule" from an-app in html file then {{ studname }} works fine but after adding "mymodule" i'm getting error

html file code :

<!DOCTYPE html>
<html ng-app="mymodule">
  <head>
    <title>Try Deep linking</title>
    <script src="angular.min.js"></script>
    <script type="text/javascript" src="route.min.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
  </head>
  <body>
    <input type="text" name="" ng-model="studname" />
    <p>{{ studname }}</p>
    <div ng-view>

    </div>
    <a href="#/view1">View 1</a>
    <a href="#/view2">View 2</a>
  </body>
</html>  

JS code :

var myapp = angular.module("mymodule",[]);

myapp.controller( "mycontroller", function ($scope) {
   $scope.student = [
      {name : "Abhay Sehgal", city: "Delhi" },
      {name : "Pankaj Singh", city: "Bihar" },
      {name : "ujjwal", city : "UP"}
   ];
});

myapp.config(function($routeProvider){
    $routeProvider
    .when('/view1',{
        controller : "mycontroller",
        templateUrl : "parts/view1.html" 
    })
    .when('/view2',{
        controller : "mycontroller",
        templateUrl : "parts/view2.html" 
    })
    .otherwise({redirectTo :'/'});
});

Thanks in advance

1 Answer 1

2

You need to add the dependency ngRoute to your module,

var myapp = angular.module("mymodule",['ngRoute']);
Sign up to request clarification or add additional context in comments.

1 Comment

solved..thanks a lot..seriously i'm doing a silly mistake...thanks once again

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.