我在客戶類型的註冊表單中有一個下拉列表。更改服務中的屬性值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
?
我嘗試了你的建議方法,但沒有運氣。我做了以下工作:我提交了第一種類型的客戶表單 - >指令已正確呈現。但是,當我改變客戶類型時,指令就像我選擇第一個選項而不是第二個選項一樣呈現。 –