如何使用AngularJS初始化SharePoint脚本编辑器WebPart内容

问题描述 投票:0回答:1

我在使用SharePoint脚本WebPart和AngularJS获取绑定初始值时遇到问题。我尝试了所有不同的方法来初始化ng-int,自定义init函数,准备好文档。在所有情况下,都将调用该函数并设置值,但是直到我再次与控制器交互时,UI才会使用这些值更新。

在下面的代码中,{{usertitle}}没有绑定。

因此,直接的问题是在SharePoint,Script WebPart和AngularJS上下文中成功初始化值的正确方法是什么?

只是为了显示加载后UI的外观,将填充其他绑定,但不填充用户名。enter image description here

单击“下一步”按钮,然后单击“上一个”(在此期间不调用该功能。)>

enter image description here

脚本编辑器中的HTML

<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------------------------------------
        };

我在使用SharePoint脚本WebPart和AngularJS获取绑定初始值时遇到问题。我尝试了所有不同的方法来初始化ng-int,自定义init函数,准备好文档。在...

angularjs sharepoint web-parts
1个回答
1
投票
© www.soinside.com 2019 - 2024. All rights reserved.