Learning AngularJS
The following are things I learned in AngularJS that are not straightforward at beginning or are things that can be easily forgotten:
- Ng-if don’t use functions to evaluate true or false
e.g. ng-if="getUser()"
http://stackoverflow.com/questions/27856927/angularjs-ng-if-difference-between-value-and-function - Adding controller to component
controller: ['$state', function ($state) {
function toprogramdetails(encId) {
$state.go('ProgramDetails', { id: encId });
}
this.toprogramdetails = toprogramdetails;
}], - Initializing values in component
controller:function () {
this.$onInit = function () {
//define default values
if ("undefined" === typeof this.clickablerow) {
this.clickablerow = false;
}
if ("undefined" === typeof this.modifyStatusAndRole) {
this.modifyStatusAndRole = this.clickablerow;
}
};
}, - Do not use custom attributes that are already prebuilt to html e.g. onclick when defining attributes for componenets or directives. This causes a console log error, uncaught referenceerror: [referenceditem] is not defined..
- When defining components names or component attribute names with camelcase e.g. programsTable, you must refer to the capatilized letter with a dash then small letter in the html.
Example: app.component('userTable', {…. } has to be referred to as <user-table>