I have this HTML code:
<select
id="common_commonbundle_standard_address_state"
ng-model="common_commonbundle_standard_address.state"
required="required"
ng-disabled="!states"
ng-options="state.name for state in states.entities"
tooltip="Estado"
tooltip-trigger="focus"
tooltip-placement="right"
wv-def="Estado"
wv-cur=""
wv-err="Error!"
wv-req="The value you selected is not a valid choice"
type="text"
class="ng-scope ng-pristine ng-invalid ng-invalid-required"
disabled="disabled"
>
<option value="" selected="selected" class="">Seleccione un estado</option>
</select>
<select
id="common_commonbundle_standard_address_city"
ng-model="common_commonbundle_standard_address.city"
required="required"
ng-disabled="!cities"
ng-options="city.name for city in cities.entities"
tooltip="Ciudad"
tooltip-trigger="focus"
tooltip-placement="right"
wv-def="Ciudad"
wv-cur=""
wv-err="Error!"
wv-req="The value you selected is not a valid choice"
type="text"
class="ng-scope ng-pristine ng-invalid ng-invalid-required"
disabled="disabled"
>
<option value="" selected="selected" class="">Seleccione una ciudad</option>
</select>
And then have this Angular code to handle them:
$scope.common_commonbundle_standard_address = {country: ""};
// Add $watch for country ng-model
$scope.$watch('common_commonbundle_standard_address.country',
function(country) {
if (country)
$http.get(Routing.generate('states') + '/' +
country).success(function(data) {
if (data.message) {
$scope.message = data.message;
} else {
$scope.states = data;
}
}).error(function(data, status, headers, config) {
if (status == '500') {
$scope.message = "No hay conexión con el
servidor.";
}
});
}, true);
// Add $watch for state ng-model
$scope.common_commonbundle_standard_address = {state: ""};
$scope.$watch('common_commonbundle_standard_address.state',
function(state) {
if (state)
$http.get(Routing.generate('cities') + '/' +
state["state"].split('.')[0] + '/' + state["state"]).success(function(data)
{
if (data.message) {
$scope.message = data.message;
} else {
$scope.cities = data;
}
}).error(function(data, status, headers, config) {
if (status == '500') {
$scope.message = "No hay conexión con el
servidor.";
}
});
}, true);
My idea is to write two different directives for `E` which do the same job
without need to rewrite the whole code any time I want to use it but I'm
not a expert on this so I need some advice. This is the only code I made so
far:
app.directive('stateSelect', function($country) {
return {
restrict: 'E',
template: '<select name="" id="" ng-model=""
ng-disabled="!states" ng-options="state.name for state in states.entities"
tooltip="">',
link: function(scope, element, attrs) {
}
}
});
And I'm not sure if it's right? Any can give me some push?
ReynierPM
Mobile: +58 424-180.56.09
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.