ionic框架中的app.js函数冲突

app.js function conflict in ionic framework

本文关键字:js 函数 冲突 app 框架 ionic      更新时间:2024-02-28

我是ionic的新手,已经成功安装并测试了我的第一个教程应用程序。在使用本教程时,我面临以下问题http://ionicframework.com/docs/guide/building.html

当我创建一个空白项目"app.js"时,会创建以下代码:

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs).
    // The reason we default this to hidden is that native apps don't usually show an accessory bar, at
    // least on iOS. It's a dead giveaway that an app is using a Web View. However, it's sometimes
    // useful especially with forms, though we would prefer giving the user a little more room
    // to interact with the app.
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      // Set the statusbar to use the default style, tweak this to
      // remove the status bar on iOS or change it to use white instead of dark colors.
      StatusBar.styleDefault();
    }
  });
});

然而,除非我删除上面的js代码,否则下面的代码将不起作用。所以我的问题是:保持上面的代码重要吗?或者我可以取消它吗?如果重要的话,我该如何维护这两个代码。

.controller('TodoCtlr', function($scope){
  $scope.tasks = [
    {title: 'Collect Coins'},
    {title: 'Read books'},
    {title: 'Go home '},
    {title: 'have dinner'}
  ];
});

谢谢你抽出时间。

如果我从运行函数代码的最后一行中删除;,代码就会工作。这一行就像文件的结尾,所以如果之后有控制器,它就不会被识别。它应该是这样的:

// run function stuff...
})
.controller('TodoCtlr', function($scope){
// your controller
}); // Here should be the end now!

来源:http://forum.ionicframework.com/t/importance-of-run-function-ionicplatform/17935/3

礼貌:http://forum.ionicframework.com/users/saimon/activity

在ionic app.js中,注入与应用程序相关的所有模块以及其他应用程序配置。

第一个代码片段是检查设备是否准备好了,所以我认为你应该放这个。

至于控制器,您可以很容易地将此代码放在controller.js文件中

只需确保这些文件包含在index.html 中

试着阅读并遵循ionic文档,因为这些文档写得很好。http://ionicframework.com/docs/