How to connect Angular controllers with Ionic 3

0

I'm starting to work with Ionic 3 in which I do not create any app.js file like I've seen in tutorials and post. I have created the file "app.js" and I have loaded it into the index.html file of my ionic application but I get an error: Uncaught ReferenceError: angular is not defined I am thinking that it is the importation or something like that ... I would like you to tell me how is the correct export of angular drivers to be able to use them in my ionic pages 3

app.js file and index.html file where I import the app.js file

angular.module('starter', ['ionic'])
.run(function ($ionicPlatform) {
    $ionicPlatform.ready(function () {
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccesoryBar(true);

        }
        if (window.StatusBar) {
            StatusBar.styleDefault();

        }
    });
})
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="UTF-8">
  <title>Ionic App</title>
  <meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">

  <link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
  <link rel="manifest" href="manifest.json">
  <meta name="theme-color" content="#4e8ef7">
 
  <!-- add to homescreen for ios -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <!-- cordova.js required for cordova apps (remove if not needed) -->
  <script src="cordova.js"></script>
  <script src="assets/js/app.js"></script><!--este es el archivo y lo importo-->
  <!-- un-comment this code to enable service worker
  <script>
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('service-worker.js')
        .then(() => console.log('service worker installed'))
        .catch(err => console.error('Error', err));
    }
  </script>-->

  <link href="build/main.css" rel="stylesheet">
  

</head>
    
asked by Choche 29.04.2018 в 04:21
source

1 answer

0

Apparently you have a confusion since the version of ionic 2 onwards began to use angular 2+ and the app.js will no longer exist since angular 2 is totally different from angularjs which is the first version where they were used the app.js files by default.

Instead of the app.js initially bring this

<!-- Ionic's root component and where the app will load -->
  <ion-app></ion-app>

This is the component that allows the initial application in ionic, this component is in the path src / app / app.component.ts

You can see the example of this application that the ionic github team has called ionic-conference -app.

    
answered by 29.04.2018 / 06:39
source