简体   繁体   中英

hybrid app using Ionic + TypeScript + Angular

Hey I had developed hybrid app using Ionic + Typescript + Angular. I used beta version of Ionic lib, it was running fine, but when i update my ionic lib beta version to 1.0.0 version, then i got following error from ionic.bundle.js

Error: [ng:areq] Argument 'AppCtrl' is not a function, got undefined http://errors.angularjs.org/1.3.13/ng/areq?p0=AppCtrl&p1=not%20a%20function%2C%20got%20undefined minErr/<@file:///E:/Yogesh/my_task/myApp/www/lib/ionic/js/ionic.bundle.js:8763:12 assertArg@file:///E:/Yogesh/my_task/myApp/www/lib/ionic/js/ionic.bundle.js:10280:1 assertArgFn@file:///E:/Yogesh/my_task/myApp/www/lib/ionic/js/ionic.bundle.js:10290:1 $ControllerProvider/this.$get

AppCtrl.ts

angular.module('starter.controllers',[]);

class AppCtrl{

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

          // Create the login modal that we will use later
          $ionicModal.fromTemplateUrl('templates/login.html', {
            scope: $scope
          }).then(function(modal) {
            $scope.modal = modal;
          });

          // Triggered in the login modal to close it
          $scope.closeLogin = function() {
            $scope.modal.hide();
          };

          // Open the login modal
          $scope.login = function() {
            $scope.modal.show();
          };

          // Perform the login action when the user submits the login form
          $scope.doLogin = function() {
            console.log('Doing login', $scope.loginData);
            $timeout(function() {
              $scope.closeLogin();
            }, 1000);
          };
    }
}

I have written my controller in Typescript and after compile it in to js and then used in my app.

App.js

in app.js i inject my controller like following:

angular.module('starter', ['starter.controllers', 'ionic')

I got solution for my problem-

module DemoNS { export class AppCtrl {

constructor($scope, $ionicModal, $timeout) {

//your stuff

}

} }

angular.module('starter.controllers',[]).controller("AppCtrl", ["$scope","$ionicModal","$timeout", DemoNS.AppCtrl]);

just make a reference to your controller in the angular way as follows and you're good to go :-)

 angular.module('starter.controllers') .controller('AppCtrl', AppCtrl); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM