Struggling with errors while setting up a new AngularJS project.
Here is the code for my app and controller;
var app = angular.module('myApp', ['localytics.directives'])
.config(['$parseProvider', function ($parseProvider) {
return $parseProvider.unwrapPromises(true);
}])
.controller('myController', function ($scope, $http, $q, $timeout) {
var simulateAjax;
simulateAjax = function (result) {
var deferred, fn;
deferred = $q.defer();
fn = function () {
return deferred.resolve(result);
};
$timeout(fn, 1000);
return deferred.promise;
};
$scope.ListOfTags = function () {
$http({
method: 'Post',
url: 'FillCategories'
}).success(function (data, status, headers, config) {
$scope.optionsFromQuery = (function () {
return simulateAjax(data);
})();
}).error(function (data, status, headers, config) {
$scope.message = 'Unexpected Error';
});
}
$scope.directiveOptions = {
no_results_text: "Error"
};
});
<div data-ng-click="ListOfTags()"></div>
Implementing Chosen.js:
<select id="select_{{ item.RowId }}" ng-model="chosenModel" chosen="directiveOptions" ng-options="item._categoryId as item._categoryName for item in optionsFromQuery" style="width:200px;">
<option value="">Select</option>
</select>
Successfully retrieving categories but encountering an exception that breaks the Angular app:
[$parse] Promise found in the expression
optionsFromQuery
. Automatic unwrapping of promises in Angular expressions is deprecated.
Subsequent attempts to retrieve categories fail. What could be causing this?