Javascript 使用jQuery将ng模型添加到div

Javascript 使用jQuery将ng模型添加到div,javascript,jquery,html,css,angularjs,Javascript,Jquery,Html,Css,Angularjs,我从angular开始,我有个问题。我有这个div。它包含div,它从角度显示{{stored}}值。在文本框中键入内容并单击按钮时 <div> <div id="hidestore">{{stored}}</div> <input id="dobind" type="text" /> <input type="button" id="showstore" value="show" /> </div> 对不起,我语

我从angular开始,我有个问题。我有这个div。它包含div,它从角度显示
{{stored}}
值。在文本框中键入内容并单击按钮时

<div>
  <div id="hidestore">{{stored}}</div> <input id="dobind" type="text" />
  <input type="button" id="showstore" value="show" />
</div>

对不起,我语法不好。我需要帮助

将jquery与angularjs一起使用不是一个好的实践。您需要为输入框创建一个
s
。然后单击按钮的功能。当您单击按钮时,将输入框文本指定给存储的<代码>ng模型

angular.module('sample',[])
.controller('sampleCnt',函数($scope){
$scope.show=函数(){
$scope.stored=$scope.text;
}
});

{{存储}}

在angularjs中使用
jquery
是一种不好的做法,但这并不是说你无法实现你正在尝试的目标。您需要对其进行预绑定,而不是在show上绑定
ng模型
。只需首先隐藏
hidestore
div,并在单击show按钮后将其显示出来,这是在
angularjs
中显示的一种非常好的方法

angular.module('myApp',[])
.controller('myAppCtrl',函数($scope){
$('hidestore').css('display','none');
$(“#showstore”)。单击(函数(){
$('hidestore').css('display','block');
});
});

{{存储}}

谢谢您回答这个问题!我假设$scope在jquery中类似于$(这个),除了$scope之外,您还可以使用@KentaNomoto使用不同的约定。有乐趣的编程。你可以用谷歌搜索出来:)
$("#showstore").click(function() {
  $("#dobind").attr("ng-model", "stored")
});