我想从我的服务器获取数据,但是我有错误。我不知道错误在哪里(coonsole不告诉我) 我想从我的服务器获取json,然后用它来显示数据。 我使用VersionCtrl但我认为我有语法错误。
我是Angular,Ionic和Javascript的新手,所以......考虑一下。
这是 list.html
<ion-view view-title="Mis Notas">
<ion-content ng-controller="VersionCtrl">
<ion-list>
<ion-item class="item-remove-animate item-icon-right" href="/#/edit/{{version.success}}" class="item" ng-repeat="version in versiones">
<i class="icon ion-ios-arrow-right"></i>
<h2>{{version.success}}</h2>
<p>{{version.version}}</p>
<ion-option-button class="button-assertive icon-left ion-trash-b" ng-click="remove(version.success)">Eliminar</ion-option-button>
</ion-item>
</ion-list>
<div class="padding">
<a class="button button-block button-positive" href="/#/create">Agregar</a>
</div>
</ion-content>
<div class="bar bar-footer bar-stable">
<a class="button button-positive icon-left ion-compose" href="/#/create">Agregar</a>
</div>
</ion-view>
app.js
(function(){
var app = angular.module('starter', ['ionic'],['starter.notestore'])
app.config(function($stateProvider, $urlRouterProvider){
$stateProvider.state('list',{
url:'/list',
templateUrl:'templates/list.html'
});
$stateProvider.state('edit',{
url:'/edit/:id',
controller:'EditCtrl',
templateUrl:'templates/edit.html'
});
$stateProvider.state('create',{
url:'/create',
controller:'CreateCtrl',
templateUrl:'templates/edit.html'
});
$urlRouterProvider.otherwise('/list');
});
app.controller('ListCtrl', function($scope, NoteStore){
$scope.notas = NoteStore.list();
});
app.controller('VersionCtrl',['$http','$scope', function($http, $scope){
$http.get('http://myurlcom/version.php') //return a json
.success(function(result){
$scope.versiones = result;
})
.error(function(result){
alert('Algo anda mal...:'+result);
});
}]);
app.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
});
}());
感谢您的帮助!
//编辑//
这是来自控制台的消息错误:
ionic.bundle.js:17917 Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:
Error: [ng:areq] Argument 'fn' is not a function, got string
http://errors.angularjs.org/1.5.3/ng/areq?p0=fn&p1=not%20a%20function%2C%20got%20string
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:13438:12
at assertArg (http://localhost:8100/lib/ionic/js/ionic.bundle.js:15214:11)
at assertArgFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:15224:3)
at Function.annotate [as $$annotate] (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17247:5)
at injectionArgs (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17956:36)
at Object.invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17987:18)
at runInvokeQueue (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17888:35)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:17897:11
at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:13691:20)
at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17878:5)
http://errors.angularjs.org/1.5.3/$injector/modulerr?p0=starter&p1=Error%3A…%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17878%3A5)
答案 0 :(得分:6)
我想我看到错误在哪里;在这一行:
var app = angular.module('starter', ['ionic'],['starter.notestore'])
添加依赖项时,只需要在第二个参数中列出一个数组,因此它应该是:
var app = angular.module('starter', ['ionic', 'starter.notestore'])