我的應用程序生成一個單詞列表並將這些單詞轉換爲鏈接。我希望用戶能夠點擊這些鏈接並將該詞用作搜索詞。如何從HTML鏈接檢索{{word.name}}?如果點擊鏈接,我不希望它生成新的頁面。我只是想能夠檢索鏈接中的文字。用動態生成的鏈接動態更新html
HTML:
<li>
<a ng-href="...">{{ word.name }}</a>
</li>
Controller.js
$scope.search = function() {
$http.post('*', $scope.formData)
.success(function(data) {
$scope.formData = {};
$scope.word = data;
})
.error(function(data) {
console.log('Error: ' + data);
});
};
Node.js的服務器代碼:
app.get('*', function(req, res)
{
//get the {{ word.name }} from the HTML and use it to search
//sql = select.....+word.name;
connection.query(sql, function (err, result, fields)
{
if(err) throw err;
res.json(result);
});
});
我不知道你的意思。你能澄清嗎? – Soubriquet
但是這是來自html方面。在服務器上,您必須檢索數據。 – DarkThanos