Cristhian Boujon
Cristhian Boujon

Reputation: 4190

Dynamic forms with Angularjs

I have a developing an app using angularJS + Symfony. From backend I have the following entities:

class Property {...}

class Land extends Property {...}

class House extends Property {...}

class Office extends Property {...}

class Field extends Property {...}

Each subclass has its own specific fields.

From frontend I need to create any subclass of property in one screen. So I would show/hidden serveral fields by the property type selected. I read about ng-show but I would like some more dynamic and general due to I will have the same problem with the "view" screen.

What do you suggest? What is the best approach?

Upvotes: 0

Views: 49

Answers (1)

Mifune
Mifune

Reputation: 128

I would use angular ui-router. This will allow you to create different states that show the different classes without your html becoming large and cumbersome.

For Example:

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"];
      }
    })
});

Upvotes: 1

Related Questions