Skip to content

Instantly share code, notes, and snippets.

@jonatasfreitasv
Created June 13, 2015 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonatasfreitasv/a9def25d006b05e0dfe5 to your computer and use it in GitHub Desktop.
Save jonatasfreitasv/a9def25d006b05e0dfe5 to your computer and use it in GitHub Desktop.
Dropdown directive
/**
* States dropdown directive
*
*/
app.directive('stateDropdown', function(){
return {
controller: function($scope, stateService) {
stateService.list()
.success(function(data, status, headers) {
$scope.states = data.states;
alert($scope.state);
})
.error(function(){
});
},
scope: {
state: '@'
},
restrict: 'A',
templateUrl: 'components/states/template/dropdown.html',
};
});
<div class="field-box">
<label>Estado:</label>
<select ng-if="states" class="span12" ng-model="state"
ng-options="o.title for o in states">
</select>
</div>
<div class="span3">
<div state-dropdown data-state='{{user.identity_data.city.state}}'></div>
</div>
/**
* States service
*
*/
app.factory('stateService',
function($http, authentication) {
var requestAll = function() {
return $http({
method: 'GET',
headers: {'X-WSSE': authentication.getWSSE()},
url: app_config.api_url + "api/states?_format=json&_username=" + authentication.getUser().username + "&_hash_password=" + authentication.getUser().password
});
};
return {
list: function(username) {
return requestAll();
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment