Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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 如何使用ng模型从AngularJS(版本1.5.5)中的父组件获取数据?_Javascript_Html_Angularjs_Angularjs Ng Model_Angularjs Components - Fatal编程技术网

Javascript 如何使用ng模型从AngularJS(版本1.5.5)中的父组件获取数据?

Javascript 如何使用ng模型从AngularJS(版本1.5.5)中的父组件获取数据?,javascript,html,angularjs,angularjs-ng-model,angularjs-components,Javascript,Html,Angularjs,Angularjs Ng Model,Angularjs Components,下面是我的代码输出的图像;我知道如何显示从父组件传递下来的数据(即,100),但我不知道如何通过ng模型显示父组件数据(即,文本框中不显示100) 以下是我的HTML和AngularJS代码: var-app=angular.module('app',[]); app.component('parentComponent'{ 控制器:“父控制器” }) .controller('parentController',函数($scope){ var$ctrl=this; $ctrl.object

下面是我的代码输出的图像;我知道如何显示从父组件传递下来的数据(即,100),但我不知道如何通过ng模型显示父组件数据(即,文本框中不显示100)

以下是我的HTML和AngularJS代码:

var-app=angular.module('app',[]);
app.component('parentComponent'{
控制器:“父控制器”
})
.controller('parentController',函数($scope){
var$ctrl=this;
$ctrl.object={first:100};
})
app.component('childComponent',{//CHILD component
绑定:{displayFirst:'='},
模板:`父值:
`,
控制器:“childController”
})
.controller('childController',函数($scope){
var$ctrl=this;
$ctrl.object={first:25};
})

{{parent.object.first}

在HTML中,属性绑定需要位于:


̶̶
{{parent.object.first}
子组件需要在以下位置使用绑定:

app.component('childComponent',{//CHILD component
绑定:{
displayFirst:“=”
},
模板:`
父值:
̶̶
`,
控制器:“childController”
})
AngularJS组件使用隔离作用域。它们不从父作用域继承属性。所有父作用域数据都必须通过绑定

演示
var-app=angular.module('app',[]);
app.component('parentComponent'{
控制器:“父控制器”
})
.controller('parentController',函数($scope){
var$ctrl=this;
$ctrl.object={first:100};
})
app.component('childComponent',{//CHILD component
绑定:{displayFirst:'='},
模板:`父值:
`,
控制器:“childController”
})
.controller('childController',函数($scope){
var$ctrl=this;
$ctrl.object={first:25};
})

{{parent.object.first}

非常感谢!我很欣慰这是一个语法错误,不是逻辑错误。xx
<div ng-controller="childController">
    ̶<̶c̶h̶i̶l̶d̶-̶c̶o̶m̶p̶o̶n̶e̶n̶t̶ ̶d̶i̶s̶p̶l̶a̶y̶F̶i̶r̶s̶t̶=̶"̶p̶a̶r̶e̶n̶t̶.̶o̶b̶j̶e̶c̶t̶.̶f̶i̶r̶s̶t̶"̶>̶
    <child-component display-first="parent.object.first">
    </child-component>
    {{ parent.object.first }}
</div>
app.component('childComponent', { // CHILD COMPONENT
    bindings: {
        displayFirst: '='
    },
    template: `
       <div>
         <label>Parent Value: </label>
         ̶<̶i̶n̶p̶u̶t̶ ̶t̶y̶p̶e̶=̶"̶t̶e̶x̶t̶"̶ ̶n̶g̶-̶m̶o̶d̶e̶l̶=̶"̶$̶c̶t̶r̶l̶.̶o̶b̶j̶e̶c̶t̶.̶f̶i̶r̶s̶t̶"̶>̶
         <input type="text" ng-model="$ctrl.displayFirst">
       </div>
    `,
    controller: 'childController'
})