I am having a problem getting initial values to bind using a SharePoint Script WebPart and AngularJS. I have tried all the different ways to initialize ng-int, custom init function, document ready. In all cases the function is being called and values set but the UI is not updating with the values until I interact with the controller again.
In the code below it is the {{usertitle}} that does not bind.
So the direct question would be what is the proper way to successfully Initialize values in the context of SharePoint, Script WebPart, and AngularJS?
Just to show what the UI does look like after load, other bindings are populated but not usertitle.
Click Next Button and then Previous (function is not called during this).
HTML in Script Editor
<div id="appDiv" ng-app="myapp">
<div id="controllerDiv" ng-controller="MyController" >
<div class="item10 mainborder">
<div ng-show=showPage1() ng-init="firstFunction(this)">
<p class="lead">Welcome {{usertitle}}!</p>
</div>
<div>
<input type="button" value="Previous" ng-click="pagePrevious()" ng-disabled=showPage1() />
<span>{{pageXofY()}}</span>
<input type="button" value="Next" ng-click="pageNext()" ng-disabled=showPage6() />
</div>
</div>
</div>
</div>
Angular Controller JS
$scope.firstFunction = function ($scope) {
//User Info-------------------------------------
var userid = _spPageContextInfo.userId;
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var requestHeaders = { "accept": "application/json;odata=verbose" };
$.ajax({
url: requestUri,
contentType: "application/json;odata=verbose",
headers: requestHeaders,
success: onSuccessUInfo,
error: onErrorUInfo
});
function onSuccessUInfo(data, request) {
$scope.usertitle = data.d.Title;
$scope.email = data.d.Email;
$scope.loginname = data.d.LoginName;
//alert(loginName);
}
function onErrorUInfo(error) {
alert("error");
}
//End USeriNfo------------------------------------
};