5 Replies Latest reply on Feb 7, 2020 1:55 PM by 1812359

    How to reference appController in a view, $root doesn't seem to work any longer?

    1812359

      Hi All,

       

      All of my viewModels have the appController added so i can reference things by calling app.functionName() or app.variable just fine.

       

      My issue is trying to reach up to this while in a view. For example, I have a listView where I want to format a particular field, so I created a function in the appController.

       

      I am trying something like:

      <oj-bind-text

      value="[[$root.formattedTime($current.data.timeVariable)]]">

      </oj-bind-text>


      That doesnt work as it doesnt like $root. If I add the formattedTime function to the viewModel the view uses then it works:

      <oj-bind-text

      value="[[formattedTime($current.data.timeVariable)]]">

      </oj-bind-text>

       

      I want to avoid copying this function to all the viewModels that need it. I gather I am missing something simple here, but it has plagued me for a while!

       

      Thanks for any help.