2015-09-20 78 views
0

我有一個使用angularJS + Symfony開發應用程序。 從後端我有以下實體:Angularjs動態表單

class Property {...} 

class Land extends Property {...} 

class House extends Property {...} 

class Office extends Property {...} 

class Field extends Property {...} 

每個子類都有其特定的領域。

從前端我需要在一個屏幕上創建屬性的任何子類。所以我會選擇屬性類型來顯示/隱藏serveral字段。我讀了關於ng-show,但我想更動態和一般,因爲我會有與「查看」屏幕相同的問題。

你有什麼建議?什麼是最好的方法?

回答

1

我會使用角度ui路由器。這將允許你創建不同的狀態,顯示不同的類,而不會讓你的html變得龐大而笨重。

例如:

myApp.config(function($stateProvider, $urlRouterProvider) { 
    // 
    // For any unmatched url, redirect to /state1 
    $urlRouterProvider.otherwise("/state1"); 
    // 
    // Now set up the states 
    $stateProvider 
    .state('Property', { 
     url: "/Property", 
    templateUrl: "partials/property.html" 
    }) 
    .state('Property.land', { 
     url: "/land", 
     templateUrl: "partials/property.land.html", 
     controller: function($scope) { 
     $scope.items = ["A", "List", "Of", "Items"]; 
     } 
    }) 
}); 
+0

聽起來不錯的解決方案。如何從組合框中顯示正確的部分?或者換句話說...我怎樣才能通過組合框中選中的選項來改變狀態? –

+1

如果給組合框中的每個選項添加'$ state.go('toState',result);'它應該可以工作。 – Mifune