2014-06-15 9 views
9

मेरे पास वास्तव में अजीब बग है, मैंने अपने मार्ग और मेरे नियंत्रक सेट किए हैं। अब मेरे पास कोई रिक्त पृष्ठ नहीं है जिसमें कोई त्रुटि नहीं है?AngularJS: ngRoute, अन्यथा काम नहीं कर रहा

index.html;

<!DOCTYPE html> 
<html ng-app="RekenTalent" lang="nl"> 
    <head> 
     <title>Rekentalent.nl: Ben jij een talent in Rekenen?</title> 
     <!-- Stylesheets --> 
     <link rel="stylesheet" type="text/css" href="/app/front/assets/stylesheets/style.css"> 
     <!-- AngularJS --> 
     <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular.min.js"></script> 
     <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular-route.min.js"></script> 
     <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.16/angular-animate.min.js"></script> 
     <!-- Controllers --> 
     <script src="/app/front/controllers/controller.js"></script> 
     <!-- Router --> 
     <script src="/app/front/router.js"></script> 
    </head> 

    <body ng-view></body> 
</html 

>

Controller.js:

/** 
* RekenTalent 
* 
* Copyright 2014 - Rekentalent.nl 
*/ 
var RekenTalent = angular.module('RekenTalentControllers', []); 

RekenTalent.controller('rekenCtrl', ['$scope', function($scope){ 

}]); 

Router.js:

var RekenTalent = angular.module('RekenTalent', [ 
    'ngRoute', 'RekenTalentControllers' 
]); 

RekenTalent.config(['$routeProvider', function($routeProvider) { 
    $routeProvider. 
    when('/index', { 
     templateUrl: '/templates/index.html', 
     controller: 'rekenCtrl' 
    }). 
    otherwise({ 
     redirect: '/index' 
    }); 
}]); 

और /templates/index.html सिर्फ कहते हैं, 'हाय'। क्या किसी को पता है कि मुझे एक खाली पृष्ठ क्यों मिलता है? इसे मुझे /index.html पर रीडायरेक्ट करना चाहिए और /index.html को टेम्पलेट के रूप में /templates/index.html का उपयोग करना चाहिए। समस्या और फिक्स क्या है?

अद्यतन:

जब मैं/सूचकांक यह काम करता है, इसलिए अन्यथा परम doesn `t काम करते हैं, क्यों नहीं करने के लिए जाना?

+0

मुझे लगता है कि यह फ़ाइल संदर्भ त्रुटि है, कृपया हमें बताएं, आपकी अनुक्रमणिका कहां है, और आपके पीसी – Milad

+0

में आपकी कोणीय स्क्रिप्ट्स और आप एक कंसोल जोड़ सकते हैं।यह जांचने के लिए कि क्या नियंत्रक को सही ढंग से निकाल दिया गया है या नहीं पर यह जांचने के लिए लॉग ('लोड') है, लेकिन फिर भी, मुझे लगता है कि इसकी प्रतिबिंब त्रुटि – Milad

+0

index.html => /app/front/templates/index.html, जब भी मैं कंसोल डालता हूं नियंत्रक में .log ('hi') मुझे कंसोल में कोई लॉग नहीं मिलता है। – DazDylz

उत्तर

16

redirectredirectTo

और यह home.template उपयोग करने के लिए समस्याओं के सभी इस तरह से बचने के लिए बेहतर है करने के लिए परिवर्तन, मैं विचार मतलब है:

आप एक index.html कि आपका पूरा होता है शामिल स्क्रिप्ट है, कोणीय, jquery, ... की तरह, और शरीर टैग में ng-view है, ठीक है?

अब, यदि आपके पास स्वागत है या इंडेक्स के लिए जो भी टेम्पलेट है, तो उस टेम्पलेट को home.html में लिखें, ठीक है? इस तरह:

index.html:

<body ng-app="yourapp"> 
    <div ng-view> 
    </div> 
</body> 

home.html

<div> 
    Welcome, user. This is index. 
    </div> 

आपका एप्लिकेशन विन्यास:

yourapp.config(function($routeProvider) { 
    $routeProvider 
     .when('/', { 
     templateUrl: 'partials/home.html', 
     controller: 'homeCtrl' 
     }) 
     .otherwise({redirectTo:'/'}); 
} 

और यह के सभी डाल करने के लिए एक अच्छा अभ्यास है आपके आंशिक फ़ोल्डर के अंदर टेम्पलेट्स, जहां पिता फ़ोल्डर में index.html शामिल है जैसे

root 
    yourAppFolder 
     1-Assets 
      Css 
      Js 

     2-Partials 
      home.html 
      login.html 

     3-index.html 
2

इसे मिला; रीडायरेक्ट रीडायरेक्ट होना चाहिए;

var RekenTalent = angular.module('RekenTalent', [ 
    'ngRoute', 'RekenTalentControllers' 
]); 

RekenTalent.config(['$routeProvider', function($routeProvider) { 
    $routeProvider. 
    when('/index', { 
     templateUrl: '/app/front/templates/index.html', 
     controller: 'rekenCtrl' 
    }). 
    otherwise({ 
     redirectTo: '/index' 
    }); 
}]); 
1

मैं उदाहरण के लिए कोड का यह नमूना है:

.config(['$routeProvider', 
function($routeProvider) { 
    console.log('routeando'); 
    //alert('otherwise' + $routeProvider.route); 
    $routeProvider. 
     when('/', {  templateUrl: 'home'}). 
     when('/route1', { templateUrl: 'route1'}). 

     /*Without the next line, redirectTo doesnt work*/ 
     when('/error', { templateUrl: 'error'}). 
     otherwise({  redirectTo: '/error'}); 
}]);  

अन्यथा केवल यदि आप पहले से ही उस मार्ग के लिए एक "जब" पैरामीटर है काम करने के लिए जा रहा है।

मुझे मेरी अंग्रेजी के लिए क्षमा करें और आपका दिन शुभ हो।

संबंधित मुद्दे