2014-12-27 2 views
0

나는 각도 js의 초보자입니다. 다음 라우팅 예제를 만들려고했지만 작동하지 않았습니다. 다음 URL http://plnkr.co/edit/dd8Nk9PDFotCQu4yrnDg?p=preview각도 라우팅 예제

// create the module and name it scotchApp 
var scotchApp = angular.module('scotchApp', ['ngRoute']); 

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

     // route for the home page 
     .when('/', { 
      templateUrl : 'pages/home.html', 
      controller : 'mainController' 
     }) 

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

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

// create the controller and inject Angular's $scope 
scotchApp.controller('mainController', function($scope) { 
    // create a message to display in our view 
    $scope.message = 'Everyone come and see how good I look!'; 
}); 

scotchApp.controller('aboutController', function($scope) { 
    $scope.message = 'Look! I am an about page.'; 
}); 

scotchApp.controller('contactController', function($scope) { 
    $scope.message = 'Contact us! JK. This is just a demo.'; 
}); 

의 예 (가) 인덱스 페이지

중 하나가 제발 도와 드릴까요
<!DOCTYPE html> 
<!-- define angular app --> 
<html ng-app="scotchApp"> 

<head> 
<!-- SCROLLS --> 
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> 
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/ 
font-awesome.css" /> 

<!-- SPELLS --> 
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script> 
<script src="script.js"></script> 
</head> 

<!-- define angular controller --> 
<body ng-controller="mainController"> 

<nav class="navbar navbar-default"> 
    <div class="container"> 
    <div class="navbar-header"> 
    <a class="navbar-brand" href="/">Angular Routing Example</a> 
    </div> 

    <ul class="nav navbar-nav navbar-right"> 
    <li><a href="#"><i class="fa fa-home"></i> Home</a></li> 
    <li><a href="#about"><i class="fa fa-shield"></i> About</a></li> 
    <li><a href="#contact"><i class="fa fa-comment"></i> Contact</a></li> 
    </ul> 
</div> 
</nav> 

<div id="main"> 

<!-- angular templating --> 
    <!-- this is where content will be injected --> 
<div ng-view></div> 

</div> 

    <footer class="text-center"> 
    <p>View the tutorial on 
    <a href="http://scotch.io/tutorials/javascript/ 
    single-page-apps-with-angularjs-routing-and-templating">Scotch.io</a></p> 


    <p>View a tutorial on <a href="http://scotch.io/tutorials/javascript/ 
     animating-angularjs-apps-ngview">Animating Your Angular Single Page App</a></p> 
</footer> 

</body> 

</html> 

입니까?

+0

그래서 무엇을 작동하지 않습니다 여기에

다른 각도 UI 라우팅 예를 들어 링크입니다? 데모는 괜찮은 것 같습니다. – dfsq

+0

네,하지만이 데모에서 코드를 복사하는 저와는 작동하지 않습니다. –

+0

콘솔에 오류가 있습니까? –

답변

0

주어진 링크에서 정확한 코드를 복사 했으므로 코드에 문제가있을 수 없습니다. html로 지정한 경로가 맞습니까?

src = "script.js"script.js의 실제 위치는 무엇입니까?

0

위의 코드는 정상적으로 작동합니다. 그래도 문제가 발생하면 오류 메시지를 친절하게 공유하십시오. 또한 클라이언트 서버 아키텍처에서이 응용 프로그램을 여는 것을 잊지 마십시오. 크롬 브라우저에서 로컬 서버 또는 플러그인을 사용해 볼 수도 있습니다. Angular UI Routing Example