我是angularJS的新手,我只是想问一下如何获得on-success属性的值,该属性将在成功的上传请求中具有JSON对象。 post-creator.template.html页面上存在“on-success”属性。
的index.html
<body>
<div>
<post-creator post-id="0"></post-creator>
</div>
</body>
这是一个post-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>
这是post-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]
});
}());
答案 0 :(得分:0)
您可以将$element
注入您的控制器,并通过attributes
将$element[0].attributes
绑定到您的指令。
function controller($http, $element) {
var attrs = $element[0].attributes;
// you own logic
}