2016-03-30 22 views
-1

Angularjs and Ionic'te yeniyim ve bu forumda ve diğer yerlerde sağlanan tüm çözümleri denedim. Çalışan bir şey göremiyorum.Tek bir angularjs dosyasından tüm denetleyicileri çağırmak

Bir kart sayfası (fotoğraf) olarak tasarlanmış bir ana sayfa ile bir uygulama geliştirmek istiyorum. Bir karta tıklandığında başka bir sayfaya yönlendiriliriz. Ben ng-view okumuştum ve birkaç ders çalıştım ve bunların hiçbiri benim için işe yaramadı. olsun bu

Index.html

<!DOCTYPE html> 
     <html ng-app="sampleApp"> 
     <head> 
      <meta charset="utf-8"> 
      <script src="js/app.js"></script> 
      <script src="js/plugins/angular.js"></script> 
      <script src="js/plugins/angular-route.js"></script> 
      <title>AngularJS Routing example</title> 
     </head> 

     <body> 

    <div class="container"> 
    <div class="row"> 
    <div class="col-md-3"> 
     <ul class="nav"> 
     <li><a href="#AddNewOrder"> Add New Order </a></li> 
     <li><a href="#ShowOrders"> Show Order </a></li> 
     </ul> 
    </div> 
    <div class="col-md-9"> 
     <div ng-view></div> 
    </div> 
    </div> 
    </div> 
    </body> 
</html> 

//Define an angular module for our app 
angular.module('sampleApp', ['ionic', 'ngRoute']) 
.config(['$routeProvider', function($routeProvider) { 
$routeProvider. 

    when('/AddNewOrder', { 
    templateUrl: 'templates/add_order.html', 
    controller: 'AddOrderController' 
}). 

    when('/ShowOrders', { 
    templateUrl: 'templates/show_orders.html', 
    controller: 'ShowOrdersController' 
    }). 

    otherwise({ 
    redirectTo: '/AddNewOrder' 
    }); 

    }]) 


.controller('AddOrderController', function($scope) { 

$scope.message = 'This is Add new order screen'; 

}) 

.controller('ShowOrdersController', function($scope) { 

$scope.message = 'This is Show orders screen'; 

}); 

ve

add_order.html 

    <h2>Add New Order</h2> 

    {{ message }} 

Ben hata app.js: Burada

bir örnek:

> > ReferenceError: angular is not defined app.js:2:5 Error: [$injector:modulerr] Failed to instantiate module sampleApp due to: 
> [$injector:nomod] Module 'sampleApp' is not available! You either 
> misspelled the module name or forgot to load it. If registering a 
> module ensure that you specify the dependencies as the second 
> argument. 
> http://errors.angularjs.org/1.2.9/$injector/nomod?p0=sampleApp 
> minErr/<@http://localhost:8100/js/plugins/angular.js:78:12 
> module/<@http://localhost:8100/js/plugins/angular.js:1529:1 
> [email protected]://localhost:8100/js/plugins/angular.js:1454:38 
> [email protected]://localhost:8100/js/plugins/angular.js:1527:1 
> loadModules/<@http://localhost:8100/js/plugins/angular.js:3622:22 
> [email protected]://localhost:8100/js/plugins/angular.js:303:7 
> [email protected]://localhost:8100/js/plugins/angular.js:3616:5 
> [email protected]://localhost:8100/js/plugins/angular.js:3556:11 
> bootstrap/[email protected]://localhost:8100/js/plugins/angular.js:1299:20 
> [email protected]://localhost:8100/js/plugins/angular.js:1314:1 
> [email protected]://localhost:8100/js/plugins/angular.js:1263:5 
> @http://localhost:8100/js/plugins/angular.js:20555:5 
> [email protected]://localhost:8100/js/plugins/angular.js:2342:7 
> createEventHandler/eventHandler/<@http://localhost:8100/js/plugins/angular.js:2613:7 
> [email protected]://localhost:8100/js/plugins/angular.js:310:11 
> createEventHandler/[email protected]://localhost:8100/js/plugins/angular.js:2612:5 

Düzenleme

ben app.js. modül bağımlılıkları gelen 'iyonik' silindi Şimdi ilk bağlantı "sipariş ekle" çalışır, ancak ikinci bağlantı "siparişi göster" değil.

+0

, ancak bir virgül her biri kapanış var. – Lex

+0

Bunu değiştirdim. hala aynı problem. – Hana

+0

jsfiddle/plunk – Abhi

cevap

0

Sana kütüphanelerin sırasını değiştirmek gerektiğini düşünüyorum: Sen zinciri için modül beyanlarını çalışıyoruz

<head> 
    <meta charset="utf-8"> 
    <script src="js/plugins/angular.js"></script> 
    <script src="js/plugins/angular-route.js"></script> 
    <script src="js/app.js"></script>  
    <title>AngularJS Routing example</title> 
</head> 
+0

hala aynı sorunu yaratabilirsiniz – Hana

+1

@Hana Uygulamanız "js/app.js" veya "app.js" içinde. Çünkü ikisine de referans veriyorsun. Aynı zamanda, "js/plugins/angular.js" de ve sonra bir CDN'den (eski bir sürümde) Angular 'e atıfta bulunuyorsunuz. Kimsenin yarısı tahmin etmeyecek bir cevap vermeden önce eşyalarınızda ciddi bir temizlik yapmanız gerekir. – Lex

+0

html'in sonunda açısal ve uygulama kitaplıklarını çoğaltıyorsunuz, nedeni olabilir. –

İlgili konular