1

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')
4
  • Try to add export modifier to class declaration typescriptlang.org/Handbook#modules-export- Commented Jun 3, 2015 at 8:33
  • If i used export then also i got error Commented Jun 3, 2015 at 9:30
  • module starter.controllers { export class AppCtrl { constructor($scope, $ionicModal, $timeout) { } } Commented Jun 3, 2015 at 9:31
  • Try to move declaration of class before declaration of controller angular.module('starter.controllers').controller('AppCtrl', AppCtrl) Commented Jun 3, 2015 at 10:10

2 Answers 2

0

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]);

Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.