Federick Jons Federick Jons - 4 months ago 38
JSON Question

Argument 'fn' is not a function, got string

I want to get data from my server, but I have an error. I don't know where the error (the coonsole doesn't tell me)
I want to get the json from my server, then use it for display the data.
I use a VersionCtrl but I think I have a syntax error.

I'm new with Angular, Ionic and Javascript so.. considerer that.

This is the 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();
}
});
});
}());


Thanks for helping me!

// EDIT //

This is the message error from the console:

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)

Answer

I think I see where an error is; on this line:

var app = angular.module('starter', ['ionic'],['starter.notestore'])

When adding dependency, you only need one array listing them in the second parameter, so it should be:

var app = angular.module('starter', ['ionic', 'starter.notestore'])