I got this from an earlier post and used it to place an "arrow" (actually the letter "V") at the center of a polyline. Using your variables:
var rise = endX - startX;
var run = endY - startY;
var angle = (180/Math.PI) * Math.atan2(run,rise);
...
textSymbol.angle = angle;