Angularjs动态表单

问题描述:

我有一个使用angularJS + Symfony开发应用程序。 从后端我有以下实体:Angularjs动态表单

class Property {...} 

class Land extends Property {...} 

class House extends Property {...} 

class Office extends Property {...} 

class Field extends Property {...} 

每个子类都有其特定的领域。

从前端我需要在一个屏幕上创建属性的任何子类。所以我会选择属性类型来显示/隐藏serveral字段。我读了关于ng-show,但我想更动态和一般,因为我会有与“查看”屏幕相同的问题。

你有什么建议?什么是最好的方法?

我会使用角度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