0
我是angularJS的新手,我只是想問我如何獲得on-success屬性的值,該屬性將在成功上載請求時擁有JSON對象。 「on-success」屬性位於post-creator.template.html頁面上。AngularJS:在控制器中獲取屬性值
的index.html
<body>
<div>
<post-creator post-id="0"></post-creator>
</div>
</body>
這是一個creator.template.html後
<form role="form">
<div class="form-group float-label-control">
<label>Title</label>
<input type="text" placeholder="Name" class="form-control" ng-model="model.post.title">
</div>
<div upload-button
url="/user_uploads"
on-success="onSuccess(response)"
on-error="onError(response)"
ng-model="onSuccess(response)"
>Upload</div>
<div class="text-center">
<button type="button" class="btn btn-default" ng-click="model.save(model.post)">Save</button>
</div>
</form>
這是後creator.component.js:
(function() {
"use strict";
var module = angular.module(__appName);
function controller($http) {
var model = this;
model.post = null;
model.save = function (post) {
//get on-success value here
//console.log(model.onSuccess);
}
}
module.component("postCreator", {
templateUrl: "components/post-creator/post-creator.template.html",
bindings: {
category: "<",
postId: "<",
subCategory: "<"
},
controllerAs: "model",
controller: ["$http", controller]
});
}());
問題還不清楚,你是否介意用更多的信息更新它,以確定你想達到的目標。 –
我只想在我的控制器model.save函數中獲取成功值,當我點擊保存按鈕時。 – MTA