gpt4 book ai didi

javascript - ng-model 和 Angular 表达式之间的区别 - {{}}

转载 作者:太空狗 更新时间:2023-10-29 15:54:11 26 4
gpt4 key购买 nike

{{}} 工作正常,但 ng-model 不是,在同一个地方。

我正在使用以下 html-

<body ng-app="crud">
Gray input fields will not be visible.
<div ng-controller="ctrl">
<input type="text" value="sdf" ng-model="asdf"/>
<h1 ng-model="asdf"></h1> <!-- this doesn't work-->
<h1>{{asdf}}</h1> <!-- this work-->
</div>
</div>
</body>

asdf 在这个 js 应用中是这样定义的

 var app = angular.module("crud", []);
app.controller("ctrl", ['$scope', function($scope) {
$scope.asdf="ankur";
}]);

谁能解释一下为什么会这样?

最佳答案

ng-model 指令用于输入字段,例如 input、select 以进行双向数据绑定(bind)并从用户那里获取输入。

作为数据绑定(bind)表达式 {{}} 或 ng-bind 指令的一种方式用于在 View 中输出数据。

var app = angular.module("crud", []);
app.controller("ctrl", ['$scope', function($scope) {
$scope.asdf="ankur";
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="crud">
Gray input fields will not be visible.
<div ng-controller="ctrl">
<input type="text" value="sdf" ng-model="asdf"/>
<h1 ng-bind="asdf"></h1>
<h1>{{asdf}}</h1>
</div>
</div>

关于javascript - ng-model 和 Angular 表达式之间的区别 - {{}},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39010634/

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