In my JS file, the code
$scope.button = id ? "Edit" : "Add";
is functioning correctly. I am trying to implement it in the View like this:
<button name="saveBtn" class="btn btn-primary"
tabindex="10">{{person.id ? 'Edit' : 'Add'}}</button>
1 - The above code snippet is not working as expected. I have tried various combinations.
2 - Should I include this code in the View or the JS file?
3 - I found a related discussion on Stack Overflow here
Question : I have initialized the init()
function in the following way. Is this the correct approach, or do you have any better suggestions?
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) {
};
});