У меня есть раскрывающийся список в моей регистрационной форме для типа клиента.Изменить стоимость недвижимости в сервисе angularjs
Я хотел бы отобразить конкретный макет на основе значения из этого выпадающего списка. Для этого я создал директиву клиента:
gasStation.directive('createMenuTree',['$log','customerType',function($log, customerType){
var template;
$log.debug(customerType.getCustomerType()+ ' from directive');
if (customerType.getCustomerType() == 'REGULAR') {template = 'dashboard/regular_dashboard.html';}
if (customerType.getCustomerType() == 'BUSINESS') {template = 'dashboard/business_dashboard.html';}
return{
templateUrl: template
}; }]);
И мой контроллер:
gasStation.controller('registrationController', ['$scope','$window','customerType', function($scope, $window, customerType){
$scope.ProcessRegistration = function(){
var url = "http://" + $window.location.host +'/pages/index.html#'+'/dashboard';
$window.location.href = url;
customerType.setCustomerType($scope.customerType);
};
}]);
И моя служба:
gasStation.service('customerType',function(){
var customerType;
return{
getCustomerType: function(){ return customerType; },
setCustomerType: function(type){ customerType = type; }
};
});
Однако, основываясь на документации, все объект службы являются одиночки.
Вопрос: как я могу обновить служебную переменную customerType
на основе выбранного значения из выпадающего списка?
Я пробовал ваш предложенный подход, но не повезло. Я сделал следующее: я отправил форму с директивой первого типа клиента ->, которая была отображена правильно. Но когда я изменил тип клиента, директива была сделана так, как если бы я выбрал первый вариант вместо второго. –