2013-11-14 6 views
0

link 에 ProLoser에서 제공하는 솔루션을 구현하려고합니다. Plunk입니다. 내 문제는 링크 아래의 하위보기에서 열기 대신 링크를 누르면 전체보기가 무시된다는 것입니다.AngularJS - 부분 및 템플릿의 중첩이 작동하지 않습니다.

이 문제를 해결하는 방법을 알아야합니다.

내 흐름은 같다 : index.html ->content.html (ng-view) ->link1/2/3.html (ng-include 사용).

내 레이아웃 :

enter image description here

에 Index.html :

<!DOCTYPE html> 
<html ng-app="webApp"> 
    <head> 
    <link rel="stylesheet" href="style.css" /> 
    <script data-require="[email protected]" data-semver="1.0.7" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script> 
    <script src="app.js"></script> 
    </head> 

    <body> 
    <header>This is header</Header>   
    <div class="content" ng-view> 

    </div> 
    </body> 

</html> 

content.html :

<div> 
    <h1>This is Content brought to you by ngView</h1> 
    <br> 
    <a href="#/sub/link1">link1</a> 
    <a href="#/sub/link2">link 2</a> 
    <a href="#/sub/link3">link 3</a> 

    <ng-include src="'/sub/'+link + '.html' "></ng-include> 

</div> 

내 코드 :

.when('/sub/:link', { 
     controller: 'LinkCtrl' 
    }) 

.when('/sub/:link', { 
     templateUrl: 'content.html', 
     controller: 'MainCtrl' 
    }) 

에 그리고 줄을 편집

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

//router logic 
webApp.config(['$routeProvider', function($routeProvider) { 
    $routeProvider. 
     when('/', { 
      templateUrl: 'content.html', 
      controller: 'MainCtrl' 
     }) 
     .when('/sub/:link', { 
      controller: 'LinkCtrl' 
     }) 
     .otherwise({redirectTo: '/'}); 
}]); 

//controllers 
webApp.controller ('MainCtrl', function ($scope, $routeParams) { 
    $scope.link = $routeParams.link 
}); 

답변

0

당신은 링크를 처리 할 수있는 LinkCtrl이없는, 당신이 변경되면 작동합니다 :

<ng-include src="'/sub/'+link + '.html' "></ng-include> 

to :

<ng-include src="link + '.html'"></ng-include> 
관련 문제