2016-06-16 3 views
1

내가 Angular.js과 임 현재 아무것도는 AngularJS와 경로에 대한 HREF를 제공하는 방법

을 ngRoute에 대해 배우려고 노력하고 있지만 표시되지 않는 새로운 오전이 app.js 설정 파일

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

// configure our routes 
    app.config(function($routeProvider) { 
    $routeProvider 

     // route for the home page 

     .when('/', { 
      templateUrl : 'index.html', 
      controller : 'mainController' 
     }) 

     // route for the about page 
     .when('/about', { 
      templateUrl : 'bb.html', 
      controller : 'loginController' 
     }) 

     // route for the contact page 
     .when('/contact', { 
      templateUrl : 'contact.html', 
      controller : 'contactController' 
     }); 
}); 

이에게 있습니다 주요 index.html을이다

<head> 
     <link href="css/bootstrap.min.css" rel="stylesheet" media="screen" /> 
     <link href="css/bootstrap-theme.min.css" rel="stylesheet" media="screen"/> 
    </head> 

     <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 

    <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular-route.min.js"></script> 

<body ng-app="myApp"> 


<h1> User :{{user}}</h1> 


<a href="#about"> 
    about 
</a> 

<h1>User :{{user}}</h1> 

    </html></body> 
</html> 

    <script src="app.js"></script> 

<script src="mainController.js"></script> 
<script src="loginController.js"></script> 

이 내 컨트롤러입니다

//mainController.js 
    app.controller('mainController',function($scope, $http) { 

     $scope.user = "user"; 
    }); 
//loginController.js 
    app.controller('loginController',function($scope, $http) { 


    $scope.user = "user"; 

}); 

이것은

노드 경로를 확인하기 때문에 대략 얻을 수 없다는 것을 나타냅니다. 약 href는 어떻게 제공해야합니까?

답변

1

당신이 당신의 HTML에서 ng-app = "blog"을 가지고 있고 당신이 당신의 js에서 angular.module("myApp",['ngRoute']);을 가지고 있기 때문에

+0

나는 편집했다 .... 이제 나는 사용자를 얻는다. ... {{user}}는 빈을 반환한다. – MrRobot9

+0

당신은 어떤 요소에 ng-controller를 추가해야한다. –

+0

그 후에, 당신은 $ scope.user를 컨트롤러를 선택하면 값이 표시됩니다. –