how to fasten shelf bracket?
If you drive screws into a stud, you generally would not use anchors. There are screws available which go right through the drywall and bite into and grip in the wood stud.  In rare cases where you might use anchors in a stud it would not be "drywall" anchors but sleeve anchors which could possibly be used in drywall (but are not the best type for drywall) but are sleeve anchors for fastening screws into hard material of considerable thickness.

Anchors described as "drywall anchors" are usually designed to clamp onto 1/2" or 5/8" drywall and depend on having empty space behind the wallboard. Anchors of this design cannot be used in drywall right over a stud because they must expand on the inside surface of the drywall and if there is a stud there they cannot expand.

Some old resinous studs become very hard with age and it can be hard to drive screws directly into such a stud without drilling a pilot hole which is a little larger than recommended (but not so large that the screws don't bite well). I nearly always use wax lubricant on screws going into studs. Once I was attaching grab bars through drywall into old, hard studs in a bathroom. I resorted to drilling 3/8" diameter holes and inserting plastic anchors in to the holes, essentially treating the wood as it it were concrete. But I was very careful to get those large holes perfectly in the center of the studs.

A drill is not the best tool to use to drive screws into a tough material. There are now "drivers" which pulse or vibrate as the screw is turned. I still don't have one and have to resort to improvising which using a proper driver renders completely unnecessary.

It is sometime necessary to drive screws at a slight angle if the holes do not exactly line up with the studs and this can be done in a way which is perfectly acceptable. But why do you think you will have to do that in your case? Please describe the exact situation you have. How far apart are the holes in the bracket and how does this match up with the location of the studs behind the drywall? How are you locating the studs?