-2

I am really new to Angular. I am trying to execute my code defined in a controller in my app.js file. I need to do that by a javascript. How to do that?

app.js file

app.controller('MyLocCtrl',function($firebaseObject){
  myfunction = function () {
const rootRef =  firebase.database().ref();
this.object = $firebaseObject(rootRef);

var myLatLng = {lat: -25.363, lng: 131.044};

var map = new google.maps.Map(document.getElementById('map'),{
  zoom: 4,
  center: myLatLng
});

var marker = new google.maps.Marker({
  position: myLatLng,
  map: map,
  title: 'Hello World!'
});

};

}

);

and my JS code in another page//map.html

    <script src="app.js"></script>
  <body ng-app="app">
    <div id="map" ng-app='app' ng-controller="MyLocCtrl"></div>
</body>

    <script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDUX6F83LCTZ7_uQlXzR6_Q2u6BXFIvGkY&callback=angular.element(document.getElementById('map')).firebaseObject().myfunction();">
    </script>

</html>
agha
  • 1
  • 2
  • No, you cannot/should not make calls into your Angular controllers from non-Angular code. Describe what problem you're actually trying to solve. You want to include the Google API and execute a function when it's loaded? – deceze Nov 25 '16 at 13:04
  • @deceze yes exactly !! now how to do so?? – agha Nov 25 '16 at 13:14

1 Answers1

0

You should have the app declared as an angular module like this:

var app = angular.module('myApp',[]);

app.controller('MyLocCtrl', ['$scope', function($scope) {
  //
}]);

After that you are able to communicate with the html

Also, you already declared ng-app='app' in the body, you should remove it from the div element

Alex
  • 166
  • 8
  • This does not in any way illustrate how to hook into the Google API callback. – deceze Nov 25 '16 at 13:17
  • He doesn't have a working JS file that will connect to HTML. I suggested to make the app module that will have the controller. The Google API callback is another part of the problem – Alex Nov 25 '16 at 13:18