I am very new to angularJs
.I understood the some concepts but still a lot of things are not clear.I am looking for your help to understand me the following scenarios with some demonstration for clear understanding.
Any help is appreciated. Thanks
I will give you a very simple account of what you can do with them.
Controllers are for handling operations related to a specific view. If you have Students Area and Teachers Area in the same markup and are operated in their own territories, you should probably go for two controllers to manage them.
controller('students', function($scope) {
//Load all students
$scope.allStudents = getAllStudents()
//Setup preferences
$scope.showAll = false;
});
Factories and Services are a great ways to break your code up in to different segments. Let's say you have lot of functions for Student Profiles and Student Scores. You can have two factories to organize them better.
studentProfiles.registerStudent(name, class);
studentProfiles.assignClass(id, class);
studentScores.getAllScores(id);
studentScores.saveScores('science', 97);
You should go for directives when you need to manipulate DOM. Angular directives are complex and have a very broad view. Things you can do with these are so much. Let's say you need to attach the image of each student in a view where their names are shown.
<div student-name id="255">
directive('studentName', function(studentProfiles){
link: function(ele, attr) {
//This line is for pseudo meaning only
ele.append('<img src="' + studentProfiles.getStudentPicture(attr.id) + ">');
}
})
There are ample of beginners guides available in the internet. Follow them and take time to do your own practice projects.