2015-05-21 54 views
1

當運行我的代碼,我得到一個空白屏幕與控制檯錯誤:黑屏離子

GET http://localhost/templates/home.html 404(未找到)

導致黑屏。代碼運行到燈服務器(本地主機)。

我的index.html:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <title></title> 

    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 
    <link href="css/index.css" rel="stylesheet"> 

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above 
    <link href="css/ionic.app.css" rel="stylesheet"> 
    --> 

    <!-- ionic/angularjs js --> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 

    <script src="lib/ngCordova/dist/ng-cordova.js"></script> 

    <!-- ngRoute error--> 
    <script src="lib/angular/angular.js"></script> 
    <script src="lib/angular-route/angular-route.js"></script> 

    <!-- cordova script (this will be a 404 during development) --> 
    <script src="cordova.js"></script> 

    <!-- your app's js --> 
    <script src="js/app.js"></script> 

    <script src="Scripts/jquery-1.11.2.js"></script> 
    <script src="Scripts/URLDecode.js"></script> 
    <script src="Scripts/serverInfo.js"></script> 
    <script src="Scripts/moment.js"></script> 

    <!-- Location of user for displaying nearby restaurants from database 
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>-->    


    <!-- 
    <script> 
      localStorage.clear(); 
    </script> 
    --> 

    </head> 

    <body ng-app="starter"> 

    <ion-nav-view></ion-nav-view> 

    <script id="templates/home.html" type="text/ng-template"> 
     <ion-side-menus enable-menu-with-back-views="false"> 
     <ion-side-menu-content> 
      <ion-nav-bar class="bar-energized"> 
      <ion-nav-back-button> 
      </ion-nav-back-button> 

      <ion-nav-buttons side="left"> 
       <button class="button button-icon button-clear ion-navicon" menu-toggle="left"> 
       </button> 
      </ion-nav-buttons> 

      </ion-nav-bar> 
      <ion-nav-view name="sidebarContent"></ion-nav-view> 
     </ion-side-menu-content> 

     <ion-side-menu side="left"> 
      <ion-header-bar class="bar-energized"> 
      <h1 class="title">Testing</h1> 
      </ion-header-bar> 
      <ion-content> 
      <ion-list> 
       <ion-item nav-clear menu-close ng-click="startRanging()"> 
       </ion-item> 
      </ion-list> 
      </ion-content> 
     </ion-side-menu> 
     </ion-side-menus> 
    </script> 

    <script id="templates/rangemodal.html" type="text/ng-template"> 

    <ion-modal-view> 
     <ion-header-bar class="bar-energized"> 
     <h1 class="title">Beacon values</h1> 
     <div class="buttons"> 
      <button class="button button-clear" ng-click="closeModal()">Close 
      </button> 
     </div> 
     </ion-header-bar> 

     <ion-content> 
     <ion-refresher spinner="lines" on-refresh="refreshData()"> 
     </ion-refresher> 

     <div class="list"> 

     <label class="item item-input item-select"> 
     <div class="input-label"> 
      Select Major value 
     </div> 
      <select ng-model="selectedBeacon" 
       ng-options="beacon.major for beacon in data"> 
       <option>--</option> 
     </select> 
     </label> 

     </div> 

     <ion-list> 
     <ion-item>Minor: {{selectedBeacon.minor}}</ion-item> 
     <ion-item>Proximity: {{selectedBeacon.proximity}}</ion-item> 
     <ion-item>RSSI: {{selectedBeacon.rssi}}</ion-item> 
     </ion-list> 

     </ion-content> 

    </ion-modal-view> 

    </script> 

<script id="templates/tester.html" type="text/ng-template"> 
    <ion-view view-title="tester"> 
    <ion-content> 
     test 
    </ion-content> 
    </ion-view> 
</script> 

    </body> 

</html> 

裏面我app.js配置:

.config(function($stateProvider, $urlRouterProvider) { 
    $stateProvider 
    .state('home', { 
    url: "/home", 
    abstract: true, 
    templateUrl: "templates/home.html", 
    controller: 'TestmenuController' 
    }) 
.state('home.tester', { 
url: "/tester", 
templateUrl: "templates/tester.html", 
controller: 'TestController' 

});

$ urlRouterProvider.otherwise('/ tester');

})

TesmenuController:

.controller('TestmenuController', function($scope, $ionicModal, BeaconData) { 

    $scope.data = BeaconData.getData(); 

    $scope.startRanging = function() { 
    BeaconData.startRanging();  
    $scope.data = BeaconData.getData(); 
    }; 

    $scope.refreshData = function() { 
    //BeaconData.resetData(); 
    $scope.data = BeaconData.getData(); 
    $scope.$broadcast('scroll.refreshComplete'); 
    if($scope.data == '') { 
     alert('No data available for region:\n01122334-4556-6778-899a-abbccddeeff0'); 
    } 
    }; 

    $scope.select = function (major) { 
    alert('click'); 
    $scope.index = data.major.indexOf(major); 
    alert(index); 
    }; 

    $ionicModal.fromTemplateUrl('rangemodal.html', { 
    scope: $scope, 
    animation: 'slide-in-up' 
    }).then(function(modal) { 
     $scope.modal = modal; 
    }); 
    $scope.openModal = function() { 
    $scope.modal.show(); 
    }; 
    $scope.closeModal = function() { 
     $scope.modal.hide(); 
    }; 
    // Cleanup the modal when we're done with it! 
    $scope.$on('$destroy', function() { 
      $scope.modal.remove(); 
    }); 

}) 

我的整個app.js

// Ionic Starter App 

// angular.module is a global place for creating, registering and retrieving Angular modules 
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) 
// the 2nd parameter is an array of 'requires' 
ionic.Platform.isReady = true; 
angular.module('starter', ['ionic', 'ngCordova', 'ngRoute']) 


.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 

    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 
    if(window.StatusBar) { 
     //StatusBar.styleDefault(); 
     StatusBar.hide(); 
    } 
    //Put on device's bluetooth 
    cordova.plugins.locationManager.isBluetoothEnabled() 
     .then(function(isEnabled) { 
     if(!isEnabled) { 
      cordova.plugins.locationManager.enableBluetooth(); 
     } 
     }) 
    }); 
}) 

.config(function($stateProvider, $urlRouterProvider) { 
    $stateProvider 
    .state('home', { 
    url: "/home", 
    abstract: true, 
    templateUrl: "templates/home.html", 
    controller: 'TestmenuController' 
    }) 

.state('home.tester', { 
url: "/tester", 
templateUrl: "templates/tester.html" 

});

$ urlRouterProvider.otherwise('/ tester');

}) 

.service('BeaconData', function() { 

    var data = []; 

    this.startRanging = function() { 

    var beaconRegion = { 

     uuid: '01122334-4556-6778-899a-abbccddeeff0', 
     identifier: '89' 
    }; 

    var delegate = new cordova.plugins.locationManager.Delegate(); 

    cordova.plugins.locationManager.setDelegate(delegate); 

    var beaconRegion = new cordova.plugins.locationManager.BeaconRegion(
    beaconRegion.identifier, beaconRegion.uuid); 

    /* Every time startRanging() is called, this section will continue to update every split second 
    if a beacon is detected for given beaconRegion*/ 
    delegate.didRangeBeaconsInRegion = function (pluginResult) { 

     var result = JSON.stringify(pluginResult); 

     var obj = JSON.parse(result); 

     for(i = 0; i < obj.beacons.length;i++) { 
     data[i] = obj.beacons[i]; 
     } 

    }; 

    cordova.plugins.locationManager.startRangingBeaconsInRegion(beaconRegion) 
    .fail(console.error) 
    .done(); 

    }; 

    this.resetData = function() { 
    data = ''; 
    } 

    this.getData = function() { 
    return data; 
    }; 

}) 

.service('Database', function() { 


}) 
/* 
.service('GeolocationService', function() { 

    var geocoder; 

    this.getLocation = function() { 

    geocoder = new google.maps.Geocoder(); 
    navigator.geolocation.getCurrentPosition(onGetCurrentPositionSuccess, onGetCurrentPositionError); 

    var onGetCurrentPositionSuccess = function(position) { 
     alert("lat: " + position.coords.latitude); 
     alert("long: " + position.coords.longitude); 
     var lat = parseFloat(position.coords.latitude); 
     var lng = parseFloat(position.coords.longitude); 


     var latlng = new google.maps.LatLng(lat, lng); 

     geocoder.geocode({'latLng': latlng}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      if (results[0]) { 
      var arrAddress = results[0].address_components; 
      // iterate through address_component array 
      $.each(arrAddress, function (i, address_component) { 
       if (address_component.types[0] == "locality") { 
       console.log(address_component.long_name); // city 
       alert(address_component.long_name); 
       return false; // break 
       } 
      }); 
      } else { 
      alert("No results found"); 
      } 
     } else { 
      alert("Geocoder failed due to: " + status); 
     } 
     }); 
    } 

    var onGetCurrentPositionError = function(error) { 
     console.log("Couldn't get geo coords from device"); 
    } 
    } 
}) 
*/ 
.controller('CheckAvailabilityController', function($scope, BeaconData) { 


}) 

.controller('StartController', function($scope, BeaconData) { 

}) 

.controller('TestmenuController', function($scope, $ionicModal, BeaconData) { 

    $scope.data = BeaconData.getData(); 

    $scope.startRanging = function() { 
    BeaconData.startRanging();  
    $scope.data = BeaconData.getData(); 
    }; 

    $scope.refreshData = function() { 
    //BeaconData.resetData(); 
    $scope.data = BeaconData.getData(); 
    $scope.$broadcast('scroll.refreshComplete'); 
    if($scope.data == '') { 
     alert('No data available for region:\n01122334-4556-6778-899a-abbccddeeff0'); 
    } 
    }; 

    $scope.select = function (major) { 
    alert('click'); 
    $scope.index = data.major.indexOf(major); 
    alert(index); 
    }; 

    $ionicModal.fromTemplateUrl('rangemodal.html', { 
    scope: $scope, 
    animation: 'slide-in-up' 
    }).then(function(modal) { 
     $scope.modal = modal; 
    }); 
    $scope.openModal = function() { 
    $scope.modal.show(); 
    }; 
    $scope.closeModal = function() { 
     $scope.modal.hide(); 
    }; 
    // Cleanup the modal when we're done with it! 
    $scope.$on('$destroy', function() { 
      $scope.modal.remove(); 
    }); 
    // Execute action on hide modal 
    //$scope.$on('modal.hidden', function() { 
    // Execute action 
    //}); 
      // Execute action on remove modal 
    //$scope.$on('modal.removed', function() { 
      // Execute action 
    //}); 
}) 
+0

這是什麼'''<離子NAV-視圖>'''???我的意思是:你爲什麼在那裏? – NietzscheProgrammer

+0

你有什麼看法嗎?如果是這樣,把它放在你的代碼中,我想我知道你的問題是什麼。我需要的只是一些更多的信息。 – NietzscheProgrammer

+0

感謝您的評論! :)這些是我迄今唯一的看法。我嘗試在這裏找到模仿代碼:http://codepen.io/mhartington/pen/azwojR?editors=101 – Theumiz

回答

2

確定讓我們看看

這是你的HTML看起來應該像

<html ng-app="ionicApp"> 
    <head> 
    //links and stuff 
    </head> 

    <body> 

    <ion-nav-view></ion-nav-view> 

    <script id="templates/home.html" type="text/ng-template"> 
     <ion-side-menus enable-menu-with-back-views="false"> 
     ... 
     </ion-side-menus> 
    </script> 

    <script id="templates/tester.html" type="text/ng-template"> 
     <ion-view view-title="TESTER"> 
     <ion-content> 
      ... 
     </ion-content> 
     </ion-view> 
    </script> 
    </body> 
</html> 

這裏的角部位

angular.module('ionicApp', ['ionic']) 

.config(function($stateProvider, $urlRouterProvider) { 
    $stateProvider 

    .state('home', { 
    url: "/home", 
    abstract: true, 
    templateUrl: "templates/home.html", 
    controller: 'TestMenuCtrl' 
    }) 

    .state('home.tester', { 
    url: "/tester", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/tester.html", 
     controller: 'TesterCtrl' 
     } 
    } 
    }); 
    // if none of the above states are matched, use this as the fallback 
    $urlRouterProvider.otherwise('/home/tester'); 
}) 

.controller('TestMenuCtrl', function($scope, $ionicModal, $timeout) { 
    // Form data for the login modal 
    $scope.loginData = {}; 

}) 

.controller('TesterCtrl', function($scope) { 
    $scope.oneAndtwo = [ 
    { title: 'one', id: 1 }, 
    { title: 'two', id: 2 }, 
    { title: 'three', id: 3 }, 
    { title: 'four', id: 4 }, 
    { title: 'five', id: 5 }, 
    { title: 'six', id: 6 } 
    ]; 
}); 

,在這裏工作的例子http://jsbin.com/diliru/1/edit?html,js,output

記得做ionic serve在你的終端,做到心中有數這個:<ion-nav-view name="menuContent"></ion-nav-view>應該是你應該放在這裏的同一個名字

.state('home.tester', { 
    url: "/tester", 
    views: { 
     'menuContent': { 
     templateUrl: "templates/tester.html", 
     controller: 'TesterCtrl' 
     } 
    } 
    }); 

記得提及你的依賴關係。

我不知道還有什麼。只要讓我知道如果我可以幫助。

+0

仍然是相同的404錯誤:'(非常感謝你的努力,但我應該在文檔中尋找更好,我想 – Theumiz

+0

@ user3725345一旦你修復它迴歸到這篇文章,並告訴我爲什麼發生這種情況。有一個很好的。 – NietzscheProgrammer

+0

@ user3725345答案哪個地址喲你關心的是這個。你應該給這個傢伙一個更好的答案。我想你是在後臺運行的另一個問題。 – TheUnnamed

0

Ionic有它自己的服務器來測試你的應用程序。 AFIK,它不是作爲普通網站/服務器運行的。作爲服務器運行只是一個工具,他們給構建應用程序更迅速

所以運行應用程序,

cd to your app folder

run ionic serve

it should start at localhost:8100默認

閱讀更多getting started

+0

完全忘了,cli命令是'ionic serve' – Theumiz

-1

你可以檢查你使用的是哪個版本的Cordova。

cordova -v 

如果版本> 4.3,嘗試添加白名單插件

ionic plugin add cordova-plugin-whitelist 

新科爾多瓦塊HTTP請求,但此錯誤時顯示的應用程序試圖發出HTTP請求。

<access origin="*" /> 

訪問起源添加到您的的config.xml文件

這應該解決問題

+0

已經添加到我的config.xml – Theumiz

+0

添加此插件,使其工作離子插件添加cordova-plugin-whitelist –

+0

我的cordova是4.3.0,運行命令時出現此錯誤:npm http GET http://registry.cordova.io/cordova-plugin-whitelist npm http 404 http:// registry .cordova.io/cordova-plugin-whitelist 錯誤:404未找到:在RegClient上的cordova-plugin-whitelist 。 (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:268:14) – Theumiz