m nwl
m nwl

Reputation: 11

I want to call an AngularJS controller to query a database in one file and use the values within another

I'm in the middle of a school project where I am reading x and y coordinates from a database and using this data and Two.JS draw a series of tables and chairs over a map image on a webpage. I've used ng-repeat to confirm that I am receiving the data I want, but cant find any way to use it in my draw script.

My HTML calls the draw script within a div (map and tablesnchairs are positioned absolutely so tablesnchairs draws on top of the map image) :

<div id="map">
    <img src="images/map.png" id="mapimg">
</div>
<div id="tablesnchairs"><script src="js/draw.js"></script></div>

<table id="test" ng-controller="TableController as tblCtrl" >
    <tr ng-repeat="table in tblCtrl.tablelist">
        <td>{{table.xco}}</td>
        <td>{{table.yco}}</td>
    </tr>
</table>

getData.js:

   "use strict";
var app = angular.module('SeatingApp', ['ngResource', 'ngStorage']);


app.factory('chairDAO', function ($resource){
    return $resource('/api/chair/:chairid');
});

app.factory('tableDAO', function ($resource){
    return $resource('/api/tables/:tableid');
});


app.controller('TableController', function(tableDAO, chairDAO, $scope){
    this.tablelist = tableDAO.query();
    this.chairslist = chairDAO.query();   

    $scope.tablelist = this.tablelist;
    $scope.chairslist = this.chairslist;

});

draw.js:

/* global Two */



    var elem = document.getElementById("tablesnchairs");


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

    var t = myApp.controller('myController', ['tablelist', function ($scope) {
        this.tablelist = $scope.tablelist;

    }]);

    var two = new Two({
    type: Two.Types.canvas,
    fullscreen: false
}).appendTo(elem);

        angular.forEach(t.tablelist, function(value){
            var temp = two.makeRectangle(value.xco, value.yco, 5, 5);
        });

        two.update();

Is there a simple way I can do this?

Upvotes: 1

Views: 39

Answers (0)

Related Questions