0
我想從回調中設置一個變量我試過$應用,但我得到錯誤,申請是衝突的,經過一些研究後,我發現我應該使用$超時而不是$應用。所以我改變了代碼,如下所示。在sharepoint 365 Angularjs
myApp.controller('dynamicCtrl', ['$scope', '$timeout', function ($scope, $timeout) {
var jsonObj = [];
jsonObj.push({
"type": "text",
"model": "text",
"label": "text",
"placeholder": "text"
});
//$scope.stdFormTemplate = jsonObj;
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
var list = web.get_lists().getByTitle('TITLE');
var listFields = list.get_fields();
clientContext.load(listFields);
ctx.load(listFields);
ctx.executeQueryAsync(function() {
onListFieldsQuerySucceeded(setJsonData);
},
function (sender, args) {
console.log(args);
});
function onListFieldsQuerySucceeded(callback) {
var type = "";
var fieldEnumerator = listFields.getEnumerator();
while (fieldEnumerator.moveNext()) {
var oField = fieldEnumerator.get_current();
var fType = oField.get_fieldTypeKind();
if (fType === SP.FieldType.choice) {
} else if (fType === SP.FieldType.text) {
}
}
callback(jsonObj);
}
function setJsonData(jsonObj) {
$timeout(function() {
alert("hithere" +jsonObj);
$scope.stdFormTemplate = jsonObj;
}, 0);
}
$scope.stdFormData = {};
$scope.urlFormData = {};
}]);
我試圖在功能setJsonData實現這一目標,我可以看到警報,但仍如預期$ scope.stdFormTemplate是不會得到更新。
我正在嘗試使用this庫。
看看Angular或jQuery中的延遲對象 – Shawn