Created
June 13, 2015 00:34
-
-
Save jonatasfreitasv/a9def25d006b05e0dfe5 to your computer and use it in GitHub Desktop.
Dropdown directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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', | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="span3"> | |
<div state-dropdown data-state='{{user.identity_data.city.state}}'></div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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