我在客户类型的注册表单中有一个下拉列表。更改服务中的属性值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
?
我尝试了你的建议方法,但没有运气。我做了以下工作:我提交了第一种类型的客户表单 - >指令已正确呈现。但是,当我改变客户类型时,指令就像我选择第一个选项而不是第二个选项一样呈现。 –