Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS:从自定义标记获取属性值_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS:从自定义标记获取属性值

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>

我是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.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,很高兴这有帮助!:)