2 回答

TA貢獻(xiàn)1856條經(jīng)驗 獲得超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>

TA貢獻(xiàn)1864條經(jīng)驗 獲得超6個贊
這比我所擁有的更接近,并為我提供了一個陣列解決方案的良好開端(謝謝,Supercool)。不完全是我所追求的。這是我從您的代碼中得到的狀態(tài):
[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”之間的每個按鍵狀態(tài)之后,所有生成的文本都將反映輸入框中的任何內(nèi)容。包括上述示例的所有這些中間狀態(tài),倒數(shù)第二個將是:
[Penultimate state. in the middle of typing out "3rd" and before pressing Go]
input box: 1st 2nd 3r
1st 2nd 3r
1st 2nd 3r
我認(rèn)為我可以獲得這種功能,因為我認(rèn)為(仍然這樣做?)角度的 {{reference}} 鏈接到原始的,并且無論你有多少,當(dāng)你制作它們等等,都會自動更新。 .
添加回答
舉報