I'm new to angular, and I'm trying to solve this problem. I have the following html
<div ng-repeat="el in elements">
<div ng-basicmenuinput basic-input="el"></div>
</div>
and in controller I have the following elements
$scope.elements = [
{
type: "A",
name: "AAA"
},
{
type: "B",
name: "BBB"
}
];
and I've created the following directive
.directive('ngBasicmenuinput', function () {
return {
restrict: 'A',
replace: true,
scope: {
basicInput: "="
},
template: function () {
return '<div class="basicMenuInput">{{basicInput.name}}</div>';
}
}
})
now on template function I want to do something like this:
template: function () {
if(basicInput.type=="A") // basicInput is undefined
return '<div class="basicMenuInput">{{basicInput.name}}</div>';
}
but basicInput is undefined. Basically all I want to do is return a different template based on basicInput.type. Is it okay( in an angular way ) what I did?