I am currently creating a search box which will give suggested list taken from database but I am having trouble getting the correct syntax in passing Python list to AngularJS module.
This is my Python List:
TaskNameList = [{'id':'1','name':'Alabama'},{'id':'2','name': 'Alaska'}]
I think I wasn't able to get the correct syntax here where the TaskNameList is from views.py:
$scope.states = {{ TaskNameList }};
And this is my complete template codes:
index.html:
<html ng-app="ui.bootstrap.demo">
<head>
<script>
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TypeaheadCtrl', function($scope, $http) {
$scope.selected = undefined;
$scope.states = {{ TaskNameList }};
// Any function returning a promise object can be used to load values asynchronously
$scope.getLocation = function(val) {
return $http.get('', {
params: {
sensor: false
}
}).then(function(response){
return response.data.results.map(function(item){
return item.formatted_address;
});
});
};
});
</script>
</head>
<body>
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<h4>Static arrays</h4>
<input type="text" ng-model="selected" typeahead="state as state.name for state in states | filter:{name:$viewValue} | limitTo:8" class="form-control">
</div>
</body>
</html>
console.log("{{ TaskNameList }}")?