使用Ionic + TypeScript + Angular的混合型应用

hybrid app using Ionic + TypeScript + Angular

本文关键字:混合型 应用 TypeScript Ionic 使用 Angular      更新时间:2023-09-26

嘿,我用Ionic + Typescript + Angular开发了一个混合应用。我使用Ionic lib的测试版,它运行良好,但当我更新我的Ionic lib测试版到1.0.0版本,然后我得到以下错误从Ionic .bundle.js

错误:[ng:areq]参数' apptrl '不是一个函数,未定义http://errors.angularjs.org/1.3.13/ng/areq?p0=AppCtrl&p1=not%20a%20function%2C%20got%20undefinedminErr/& lt; @file:///E:/优/my_task/myApp/www/lib/离子/js/ionic.bundle.js: 8763:12assertArg@file:///E/优/my_task/myApp/www/lib/离子/js/ionic.bundle.js: 10280:1assertArgFn@file:///E/优/my_task/myApp/www/lib/离子/js/ionic.bundle.js: 10290:1ControllerProvider/这。美元

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

我已经用Typescript写了我的控制器,然后把它编译成js,然后在我的应用程序中使用。

App.js

在app.js我注入我的控制器如下:

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

我的问题解决了-

module DemoNS {导出类AppCtrl {

constructor($scope, $ionicModal, $timeout) {
//your stuff
}

}}

angular.module("starter.controllers",[])。控制器("AppCtrl"("$"范围,"ionicModal美元","超时"美元,DemoNS.AppCtrl]);

只要按如下方式引用你的控制器,就可以了:-)

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