0

I have directive i am binding the attribute and object name in expression. I need to convert both value to lowercase. i tried using filter on that. It's not working. Even i tried using $filter service also it's not working. Please help anyone to achieve this.

Thanks in advance..

Directive Code:

 bosAppModule.directive('layoutTableCellControlControlRender',['$compile','$filter', function($compile,$filter){
    var layoutTableCellControlRenderObj={};
    linkFnTableCellControlRender=function(scope, element, attributes) {
        scope.controlData="NOCONTROLDATA";
        scope.kendoOptions={};   
        //scope.field = $filter('lowercase')(scope.field);
    };  
    layoutTableCellControlRenderObj.scope={field:"@",tranobj:"@" };
    layoutTableCellControlRenderObj.restrict='AE';
    layoutTableCellControlRenderObj.replace='true';
    layoutTableCellControlRenderObj.template="<div field={{tablecellcontrol.attributename | lowercase }} tranobj={{tablecellcontrol.objectname | lowercase}}>" +
                                            "</div>";
    layoutTableCellControlRenderObj.link = linkFnTableCellControlRender;

    return layoutTableCellControlRenderObj; 
}]);
shershen
  • 9,875
  • 11
  • 39
  • 60
bagya
  • 383
  • 1
  • 11
  • 38
  • Where is your filter definition? – Chris Hermut May 04 '16 at 10:50
  • @ChrisHermut It is inside template field={{tablecellcontrol.attributename | lowercase }} tranobj=**{{tablecellcontrol.objectname | lowercase}} – bagya May 04 '16 at 10:53
  • @ChrisHermut - I hope you got my issue. – bagya May 04 '16 at 11:19
  • But do you get 'tablecellcontrol.attributename' value in the output correctly (without lowercase applied)? I am just checking if you have the data in place correctly – shershen May 04 '16 at 11:35
  • @shershen - yes i'm getting that data – bagya May 04 '16 at 11:40
  • @shershen If i will add filter on that like {{tablecellcontrol.attributename | lowercase }} then only it's not binding the data. it's binding same expression instead of value. – bagya May 04 '16 at 11:41

1 Answers1

0

You should check What is the difference between '@' and '=' in directive scope in AngularJS?

And use in that parameter = for those scope properties definitions for Two-way model binding

layoutTableCellControlRenderObj.scope={field:"=",tranobj:"=" };

Check this simplified demo here: http://jsfiddle.net/juanmendez/k6chmnch/

Community
  • 1
  • 1
shershen
  • 9,875
  • 11
  • 39
  • 60
  • Yeah..two way binding is ok. but why filter is not working in expression? – bagya May 04 '16 at 11:51
  • because you're not passing the value if you use @, you should use **=** – shershen May 04 '16 at 11:54
  • I tried using "=". Then i am getting error - Syntax Error: Token '{' invalid key at column 2 of the expression [{{tablecellcontrol.attributename}}] starting at [{tablecellcontrol.attributename}}].https://docs.angularjs.org/error/$parse/syntax?p0=%7B&p1=invalid%20key&p2=2&p3=%7B%7Btablecellcontrol.attributename%7D%7D&p4=%7Btablecellcontrol.attributename%7D%7D – bagya May 04 '16 at 12:01
  • otherwise ..is it possible to use filter in ng-model? – bagya May 04 '16 at 12:27
  • what you're trying to achieve? – shershen May 04 '16 at 12:30
  • I'm trying to achieve application form in two way binding. This fields i will access from factory there i will bind this field and tranobj name to control like layoutControlsFactory.ThirdPartyReadOnly=function(controlId){ console.log("## Create ThirdPartyReadOnly"); var template=''; return template; }; – bagya May 04 '16 at 12:35