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?
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
Post a Comment