I know there is other answers on this question, but i need to do it a in specific way. I started already and i'm almost there but need some advice.
So here is my Controller :
angular.module('dynamicForm.home-ctrl',[])
.config(['$routeProvider', function($routeProvider){
$routeProvider.when('/', {
templateUrl: 'app/home/home.html',
controller: 'HomeController'
})
}])
.controller('HomeController', ['$scope','$http', 'fileName', function($scope, $http, fileName){
$http.get(fileName)
.then(function(response){
$scope.content = response;
});
}])
The JSON string has elements like this one :
[
{
"id": "1",
"title": "First Name",
"summaryTitle": "First Name",
"sort": "100",
"paramName": "fname",
"type": "text",
"image": "icon-Profile",
"placeholder" : "ex. John",
"required": true
},
{
"id": "2",
"title": "Last Name",
"summaryTitle": "Last Name",
"sort": "200",
"paramName": "lname",
"type": "text",
"placeholder" : "ex. Smith",
"required": true
}
],
And here is my custom directive ->
.directive('dynamic-tag',[function() {
var getTemplate = function (tag) {
var template = '';
if (tag.type === 'text') {
template += angular.element(tag.title + '<br />' + '<input type="'
+ tag.type + '" id="'
+ tag.id + '" title="'
+ tag.summaryTitle + '" name="'
+ tag.paramName + '" placeholder="'
+ tag.placeholder + '" required="'
+ tag.required + '" /><br />');
}
return template;
};
}]);
So how i'm suppose to use this custom tag into my template so to render every new element as a html element. Should i use ng-repeat and if yes how exacly?
If its possible keep your answers as much as can near to my logic if its possible.
Thanks in advance ! :)
P.S. --> JSFiddle - https://jsfiddle.net/jevccgxw/1/