1

I'm new to angular, trying to bind an an element's content into the controller's Scope to be able to use it within another function:

here is the scenario am working around:

I want the content of the <span> element {{y.facetName}} in

<span ng-model="columnFacetname">{{y.facetName}}</span>

to be sent to the controller an be put in the object $scope.columnFacetname in the controller

Here is a snippet of what I'm working on:

<div ng-repeat="y in x.facetArr|limitTo: limit track by $index ">
        <div class="list_items panel-body ">
            <button class="ButtonforAccordion" ng-click="ListClicktnColumnFilterfunc(); onServerSideButtonItemsRequested(ListClicktnColumnFilter, myOrderBy)">
                <span>{{$index+1}}</span>
                <span ng-model="columnFacetname">{{y.facetName}}</span>
                <span>{{y.facetValue}}</span>
            </button>
        </div>
</div>

angular.module('mainModule').controller('MainCtrl', function($scope, $http) {
                $scope.columnFacetname = "";
                $scope.ListClicktnColumnFilter = "";
                $scope.ListClicktnColumnFilterfunc = function() {
                    $scope.ListClicktnColumnFilter = "\":\'" + $scope.columnFacetname + "\'";
                };
            }

the problem is that the $scope.ListClicktnColumnFilter doesn't show the $scope.columnFacetname within it, meaning that the $scope.columnFacetname is not well-binded.

4
  • 1
    you are looping via ng-repeat so how to you expect to map multiple/different y.facetName values to map to single columnFacetname variable? Commented May 19, 2015 at 8:43
  • Did you try to just remove the "ng-model" ? Commented May 19, 2015 at 8:52
  • yes i did, but nothing changed; Commented May 19, 2015 at 11:22
  • @kachhalimbu I am mapping the item that is clicked, and it works. when the element is clicked the value will be added to the scope's object.. Thank you anyway :) Commented May 19, 2015 at 11:24

1 Answer 1

2

In your ng-click instead of calling two different function

ng-click="ListClicktnColumnFilterfunc(); onServerSideButtonItemsRequested(ListClicktnColumnFilter, myOrderBy)"

you can declare like this

ng-click="columnFacetname = y.facetName; onServerSideButtonItemsRequested(columnFacetname , myOrderBy)"

You are trying to pass that model to another function by assigning it to ListClicktnColumnFilter in your controller

By doing in this way, you can achieve the same thing.

I have done one plunker with sample array,

http://embed.plnkr.co/YIwRLWXEOeK8NmYmT6VK/preview

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

That is correct @Alhuck A , I used that way and it worked.. Here is how i used it ng-click="ListClicktnColumnFilterfunc(x.facetOuterName,y.facetName)" Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.