我想在单击它时突出显示整个单词并将其保存到某个变量中,以便我可以用它做一些事情。我不知道从哪里开始,因为我是 Angular 的新手。
最佳答案
这是我尝试完全使用 Angular
var app = angular.module('myApp', [])
app.controller('mainCtrl',['$scope' , function($scope) {
var text = "a bit of text here";
$scope.textArray= text.split(" ");
$scope.print = function(t){
// this function fetches the word, you can do anything with variable `t`
console.log(t); // for instance I output it in the console
}
}])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script>
<div ng-app="myApp" ng-controller="mainCtrl">
<p>
<span ng-repeat="t in textArray" ng-click="print(t)">{{t}} </span>
</p>
</div>
关于javascript - 单击时 Angular 突出显示整个单词并在控制台中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34116039/