gpt4 book ai didi

javascript - 在 Angular 中使用 NodeJS 数据

转载 作者:太空宇宙 更新时间:2023-11-04 03:30:19 25 4
gpt4 key购买 nike

我有以下路线:

服务器

app.get('/claim/:id', compact.js(['global']), indexController.claim);
module.exports.claim=function(req,res){
res.render('claim-note', { title: 'claim', noteId:req.params["id"]});
};

现在,我想在我的 Angular Controller 中使用 noteId 变量。喜欢:

客户端

controller("NoteController", ["$scope", "$http", function($scope, $http){
$scope.noteId = {{noteId}};
}

我怎样才能做到这一点?这个想法是用户使用像 Claim/866317 这样的直接链接,因此,已经知道页面何时打开。

最佳答案

我通常使用以下方法来解决这个问题:

controller("NoteController", ["$scope", "$http", function($scope,
$http){
$scope.setNoteId = function(noteId) {
$scope.noteId = noteId;
}
}

在 HTML 中:

<body ng-controller="NoteController" ng-init="setNoteId({{noteId}})">
...
</body>

关于javascript - 在 Angular 中使用 NodeJS 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38999148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com