I am learning Angular 1.5 and js at the same time. I am assigning some defaults from notify.js. I have code that has no errors, but I have a feeling the else if could be done in a better way. Also, as soon as I try and put returns in, I get errors. Could someone please show me the best way to do the if else and where the returns go (bottom or inline?). I still always have a hard time with ending the functions and semicolons. I know these look odd but, no errors.
Thank you.
function NotificationService ($scope, $) {
var vm = this;
/**
* @see notifyjs.com
*/
vm.publish = function (type) {
if (type === 'info') {
$.notify.defaults({
scope: $scope,
className: 'info',
autoHide: true,
position: 'bottom'
});
}
else if (type === 'success') {
$.notify.defaults({
scope: $scope,
className: 'success',
autoHide: true,
position: 'bottom'
});
}
vm.publishNoClose = function () {
$.notify.defaults({
scope: $scope,
className: 'warn',
autoHide: true,
position: 'bottom'
});
};
vm.publishNoCloseAlert = function () {
$.notify.defaults({
scope: $scope,
className: 'error',
autoHide: false,
position: 'middle'
});
};
};
}
答案 0 :(得分:1)
Just do:
$.notify.defaults({
scope: $scope,
className: type,
autoHide: true,
position: 'bottom'
});
}
They share everything but the class name.