javascript - Ternary operator and code suggestion needed -


in js file $scope.button = id ? "edit" : "add"; working fine. want use in view

    <button name="savebtn" class="btn btn-primary"  tabindex="10">{{person.id ? 'edit' : 'add'}}</button> 

1 - above code not working. tried different combinations.

2 - should use view or js file keep code?

3 - applying code here

question : have initialized init() function below. correct approach or have better share?

app.controller('personctrl', function ($scope, $routeparams, personservice) {      list();     function list() {         var id = ($routeparams.id) ? parseint($routeparams.id) : 0;         if (id > 0) {             $scope.person = {};             $scope.person = personservice.getpersonbyid(id);         } else         //$scope.people = [];         $scope.people = personservice.getpeople();     };      $scope.edit = function () {      };      $scope.delete = function (id) {      };  }); 

the syntax used inside handlebars {{}} not full javascript, angular expression language. ternary operator not available in expression language (but coming soon). can use syntax instead:

{{ person.id && 'edit' || 'add' }} 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -