Question

For the following code snippet, how can i trigger both isEditable = !isEditable and edit(object); on span click. If I'l only pass a single action in the conditional ng-click it work fine, but how can I pass 2 or more action to be triggered?

The problematic attribute is the following one: ng-click="session.falg == true||isEditable = !isEditable;edit(object);"

What I would expected here is for the isEditable value to be toggeled and the edit(object) method to be called.

Note that the session.flag is available at the rootScope level, and edit(object) is available at the controller level in charge of this view.

<ul class="list">
  <li ng-repeat="object in objectsArray">
    <div ng-show="!isEditable">
        <span ng-click="session.falg == true||isEditable = !isEditable;edit(object);">&nbsp;({{object.text}})</span>
    </div>
    <div ng-show="isEditable">
       <input type="text" ng-model="object.text" ng-blur="isEditable = !isEditable;updateObject(object);" />
    </div>
  </li>
</ul>

Thanks


The problem with having a single function to deal with this is that the 2 divs are part of a list (2 divs like the ones mentioned above will be displayed for each object available in my list ). So I'm not sure how to toggle the isEditable value(unique to each list element) with this approach.

An option will be to define an array for this value but I believe it gets to cumbersome.

Any ideas?

Thanks

No correct solution

OTHER TIPS

I strongly recommend to avoid multiple actions written into HTML.

By following approach you lose:

  • maintainability
  • you can't debug
  • code reuse
  • code organization

Like @Gruff Bunny says, create one method in controller that you call on ng-click.

Make your code simple.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top