I'm using angularJS to make a SAP. The problem I am having is within one of my template files.
I want to set the value of ng-click directive using a variable declared in that controller. Based on the change in the value of that variable the value of ng-click should change. Here's an example of the problem:
<p>Set page content template via button click</p>
<!-- Actual values of ng-click without variables -->
<button ng-click="template='page1'">Show Page 1 Content</button>
<button ng-click="template='page2'">Show Page 2 Content</button>
<!-- What I have tried
Declaring a scope variable 'page', and setting it's value to 'page1' as
$scope.page = "page1";
<button ng-click="template=page">Show Page 1 Content</button>
<button ng-click="template='{{page}}'">Show Page 1 Content</button>
<button ng-click="template=(page)">Show Page 1 Content</button>
Also tried declaring the variable as
$scope.page = "template='page1'"; or $scope.page = template='page1'
And inject like:
<button ng-click=page>Show Page 1 Content</button>
and also using (page), {{page}}, page ; with and without quotes
-->
<ng-include src="template"></ng-include>
<script type="text/ng-template" id="page1">
<p>This is content of page 1</p>
</script>
<script type="text/ng-template" id="page2">
<p> This is content of page 2</p>
</script>
The value of ng-click should be based on what is the value of that variable assigned to it.
Edit:
Just found out that we can only make calls to functions, using ng-click directive, and not to a variable. So, a variable can't be assigned. But I can't say if it's still true, and there is still no way to do it.
Question Link: Angular JS set dynamic value into ng-click directive
But is there any other way I can achieve this. Any help will be really appreciated. Thank you.