AnsweredAssumed Answered

Why is this promise with angular and the esriLoader not returning the query results I expect?

Question asked by nschmidt on Mar 14, 2017
Latest reply on Mar 16, 2017 by nschmidt

I believe I am missing a subtlety in promise chaining when working with the Angularjs esri loader.


Take this example.  It is an angular (1.x) service class.  Note the console.assert on line 17.  I was expecting the GetTestQuery function to return a promise that would resolve to an esri Query object, but this is not what is happening.  Can anyone help me understand what I am missing?


module Demo.Test {
    export class EsriFeatureServiceUtilities {

        static $inject = ['esriLoader'];
        constructor(private esriLoader: any) {

        public RunTestQuery(url: string) {
            var where = "1 = 1";
            return this.QueryTestWithWhere(url, where);

        private QueryTestWithWhere(url: string, where: string) {

            return this.GetTestQuery("1=1").then((query) => {
                console.assert(query.where == "1=1", "Why am I not getting a query object back like I expect?");
                return this.QueryTestLayer(url, query);

        private QueryTestLayer(url: string, query: __esri.Query) {
            return this.esriLoader.require(["esri/tasks/QueryTask"],
                function (QueryTask) {

                    var queryTask = new QueryTask({ url: url });
                    return queryTask.execute(query);


        private GetTestQuery(where: string) {

            return this.esriLoader.require(["esri/tasks/support/Query", "esri/geometry/SpatialReference"],
                function (Query, SpatialReference) {
                    var query: __esri.Query = new Query();
                    query.outFields = ["*"];
                    query.returnGeometry = true;
                    query.where = where;
                    query.outSpatialReference = new SpatialReference(4326);
                    return query;


    angular.module('Demo.Test').service('EsriFeatureServiceUtilities', EsriFeatureServiceUtilities);