2016-08-09 5 views
0

私のionicアプリケーションのapp.jsにファクトリを設定しようとしています。私は、私の州のプロバイダが私を投げている私の州があるべきであるかわからない私を投げているしかし、動作する必要があります次のコードがあります。このapp.jsコードを使用して工場を稼働させることを提案しましたが、私のルートに余裕はありません。私はlckなしで次のさまざまなバリエーションを試しました。あなたは事前にThnk。app.jsとstateProviderのファクトリに関する設定問題

(function() { 
    'use strict'; 

    angular 
    .module('starter', []) // In your real application you should put your dependencies.. ['ng...'] 
    //.run(runFunction) // Just commenting to make it WORK HERE 
    .controller('MainCtrl', MainCtrl) 
    .factory('myService', myService); 

    // Just commenting to make it work here.. 
    /*function runFunction($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 && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     cordova.plugins.Keyboard.disableScroll(true); 

     } 
     if (window.StatusBar) { 
     // org.apache.cordova.statusbar required 
     StatusBar.styleDefault(); 
     } 
    }) 
    }*/ 


    MainCtrl.$inject = ['$scope', 'myService']; 

    function MainCtrl($scope, myService) { 
    function getSuccess(response) { 
     $scope.items = response.data; 
    } 

    function getError(response) { 
     console.log('Of course an error since the url is a invalid, but it should work with a valid url!'); 
    } 

    myService.getAll() 
     .then(getSuccess) 
     .catch(getError); 
    } 

    function myService($http) { 
    var factory = { 
     getAll: getAll 
    }; 

    return factory; 

    function getAll() { 
     return $http.get("url"); // it -> should be your URL 
    } 
    } 
})(); 


// dont know where the config goes? 

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

    $stateProvider 

    // setup an abstract state for the tabs directive 
    .state('tab', { 
    url: '/tab', 
    abstract: true, 
    templateUrl: 'templates/tabs.html' 
    }) 

    .state('login', { 
     url: "/login", 
     cache: false, 
     controller: 'AccountCtrl', 
     templateUrl: "templates/login.html" 
    }) 

    .state('list', { 
     url: "/list", 
     cache: false, 
     controller: 'ListCtrl', 
     templateUrl: "templates/list.html" 
    }) 

    $urlRouterProvider.otherwise('/tab/dash'); 

}); 

答えて

0

あなたのアプリにui.routerが含まれているとは思われません。 $ stateProviderを使用するには、ui.routerモジュールを必要に応じて配置し、プロジェクトにangular-ui-router.jsファイルを含める必要があります。

angular 
    .module('starter', ['ui.router']) // In your real application you should put your dependencies.. ['ng...'] 
    //.run(runFunction) // Just commenting to make it WORK HERE 
    .controller('MainCtrl', MainCtrl) 
    .factory('myService', myService); 

は、$ stateProviderを提供するモジュールです。

この後、.configは.controller.factoryのようなモジュールに進むことができます。 Configもあなたに定義されています。

angular.module('starter', ['ui.router']) 
     .config(configFn) //configFn is the function you have in your .config 
     .controller('MainCtrl', MainCtrl) 
     .factory('myService', myService); 
+0

私はこれを試してみましたが、私も関数でラップしようとしました。私は '予期しないトークン 'を取得し続ける。 –

+0

どのような予期しないトークン??あなたのファイルが正しく句読点になっていますか? –

+0

はい、ドットが問題を引き起こしています。その適切な区切り。 –

関連する問題