2 回答
![?](http://img1.sycdn.imooc.com/533e4bec0001ae5302000200-100-100.jpg)
TA贡献1856条经验 获得超5个赞
这是工作示例:https ://www.w3schools.com/code/tryit.asp?filename=GD4KGYTO3RCF
还有一个片段
<!DOCTYPE html>
<html>
<!--module starts surrounds body tag name is myapp -->
<body ng-app="myapp">
<!--controller surrounds the div tag ,A controller is associated with module for functionality purpose-->
<div ng-controller="myctrl">
<form >
Input something in the input box <br><br>
Name: <input type="text" ng-model="newNodeName">
<!-- we use ng click for click in angular js -->
<button id="btn-newTransation" type="button"
ng-click="linkPairing()">Go</button>
</form>
<!-- ng-repeat repeats the html inside it , nodes is array, node is each iteration's value , track by $index to avoid duplication error and get index
ng-repeat="node in nodes"
-->
<!--ng repeat usually expects array but to just repeat an element some time this will work as shortcut-->
<div ng-repeat="x in [].constructor(count) track by $index" class="nodes">
<p>{{newNodeName}}</p>
</div>
{{message}}
<!-- i dont know why are you using following tags for -->
<div hidden>
<span class="hiddenNodeName">{{newNodeName}}</span></div>
<p class="transaction"></p>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
<script>
//initializing the myapp with controller
angular.module("myapp",[]).controller("myctrl",function($scope){
//variables in $scope are accessible in html example inside interpolation {{newNodeName}}
$scope.message="";
$scope.count=0;
$scope.linkPairing=function(){
$scope.count++;
if($scope.count==3){
$scope.message="Did it work? if it worked please upvote and mark it as correct "
}
}
});
</script>
</body>
</html>
![?](http://img1.sycdn.imooc.com/533e50ed0001cc5b02000200-100-100.jpg)
TA贡献1864条经验 获得超6个赞
这比我所拥有的更接近,并为我提供了一个阵列解决方案的良好开端(谢谢,Supercool)。不完全是我所追求的。这是我从您的代码中得到的状态:
[State 1., after typing "1st" and pressing Go]
input box: 1st
1st
[State 2. after adding "2nd," and pressing Go]
input box: 1st 2nd
1st
1st 2nd
[End State. after adding "3rd," and pressing Go]
input box: 1st 2nd 3rd
1st
1st 2nd
1st 2nd 3rd
我想看到的是:
[State 1., after typing "1st" and pressing Go]
input box: 1st
1st
[State 2. after adding "2nd," and pressing Go]
input box: 1st 2nd
1st 2nd
1st 2nd
[End State. after adding "3rd," and pressing Go]
input box: 1st 2nd 3rd
1st 2nd 3rd
1st 2nd 3rd
1st 2nd 3rd
此外,在按下“Go”之间的每个按键状态之后,所有生成的文本都将反映输入框中的任何内容。包括上述示例的所有这些中间状态,倒数第二个将是:
[Penultimate state. in the middle of typing out "3rd" and before pressing Go]
input box: 1st 2nd 3r
1st 2nd 3r
1st 2nd 3r
我认为我可以获得这种功能,因为我认为(仍然这样做?)角度的 {{reference}} 链接到原始的,并且无论你有多少,当你制作它们等等,都会自动更新。 .
添加回答
举报