gpt4 book ai didi

javascript - 隔离范围双向绑定(bind)在 angularjs 中不起作用

转载 作者:行者123 更新时间:2023-11-30 11:53:29 25 4
gpt4 key购买 nike

我是 angularjs 的新手。我正在使用隔离范围。使用独立范围的两种方式绑定(bind)不起作用。请检查我的代码。如果我删除 age : '=' 那么我的代码工作正常。

**HTML**

<div ng-controller="homeCtrl">
<my-dir name="{{namee}}" age="{{age}}"></my-dir>
</div>

**JS**

var app = angular.module("home")
app.controller("homeCtrl",["$scope",function($scope){
$scope.namee = "John";
$scope.age= 30;
}]);

app.directive("myDir",function(){
return{
restrict :'E',
scope: {
name : '@',
age : '=',
},
template: ['Directive name is: {{name}}',
'<p>{{age}}</p>'
]
}
})


**Output**

John 30
Directive name is: {{name}} {{age}}

最佳答案

应该是:

<div ng-controller="homeCtrl">
<my-dir name="name" age="age"></my-dir>
</div>

关于javascript - 隔离范围双向绑定(bind)在 angularjs 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38784480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com