Javascript AngularJS:从自定义标记获取属性值
我是AngularJS的新手不知道我做错了什么这是我的代码。基本上,我正在尝试从index.html获取post id的属性值,并从控制器在控制台中打印它 在my index.html中:Javascript AngularJS:从自定义标记获取属性值,javascript,angularjs,Javascript,Angularjs,我是AngularJS的新手不知道我做错了什么这是我的代码。基本上,我正在尝试从index.html获取post id的属性值,并从控制器在控制台中打印它 在my index.html中: <post-creator post-id="5" category="1"></post-creator> <script src="components/post-creator/post-creator.component.js"></script>
<post-creator post-id="5" category="1"></post-creator>
<script src="components/post-creator/post-creator.component.js"></script>
post-creator.component.js:
function controller($http) {
var model = this;
model.$onInit = function () {
console.log("id again:" + model.postId);
}
module.component("postCreator", {
templateUrl: "components/post-creator/post-creator.template.html",
bindings: {
value: "<"
},
controllerAs: "model",
controller: ["$http", controller]
});
函数控制器($http){
var模型=此;
型号$onInit=功能(){
console.log(“再次id:+model.posted”);
}
组件(“后处理器”{
templateUrl:“组件/post creator/post creator.template.html”,
绑定:{
值:“因为在HTML中,您传递的是post id=“…”category=“…”
,所以它们应该是组件的绑定的一部分,而不是值
。如下所示:
bindings: {
postId: "<",
category: "<"
}
绑定:{
postId:“您的绑定
不应该包含postId
而不是值
?您能给我举个例子吗?作为答案添加了这个。谢谢您的示例。我没有注意到。np,很高兴这有帮助!:)