I have a json structure and from that, i am creating a form using controllers and routes. The json is :
[{
"name": "home",
"section": "link"
},
{
"name": "about",
"section": "link"
},
{
"name": "Style",
"section": "link"
},{
"name": "name",
"type": "text",
"section": "home"
},
{
"name": "age",
"type": "text",
"section": "home"
}]
And the js code is :
var myApp = angular.module("myApp", ['ngRoute']);
myApp.controller("linkCtrl", function($scope, dataService, $route) {
dataService.getData('json/link.json', function(data){
$scope.links = data.data;
$scope.message = "home";
});
});
and my HTML code is :
<h4>{{message}}</h4>
<div ng-repeat="item in links">
<div ng-if="item.section == 'home'">
<div ng-switch="item.type">
<div ng-switch-when="text">
<input type="text" id={{item.name}} />
</div>
<div ng-switch-when="button">
<button id={{item.name}}>{{item.name}}</button>
</div>
<div ng-switch-when="checkbox">
<input type="checkbox" id={{item.name}} />
</div>
</div>
</div>
This code is working fine. If i use ng-if="item.section == {{message}}" or ng-if="item.section == '{{message}}'", its not working, but outside ng-if, if i put {{message}}, it shows "home".
Why it is not working inside ng-if statement. The basic syntax are mentioned in my code itself. I just posted the main code of my function
If the code works inside the ng-if, then it will be easy to use one template for my pages.
So, is there any way to make it work?
item.section == message