简体   繁体   English

如何在节点应用程序的客户端的我的angularJS文件中引用Javascript路由文件?

[英]How do I reference a Javascript routes file in my angularJS file on the client side in a node app?

Using require or import seems to disable the controllers in the angular file. 使用require或import似乎禁用了角度文件中的控制器。

I need to access the results from a route and display part of those results to the view using angular binding, for example I want to put the username from the authentication route response on the front page in this single page application. 我需要从路由访问结果,并使用角度绑定将这些结果的一部分显示到视图中,例如,我想将身份验证路由响应中的用户名放在此单页应用程序的首页中。

 // var users = require('.../controllers/users'); // import users from ...controllers/users.js var app = angular.module('myApp', []); app.controller('UserController', function($scope) { $scope.name = "John Doe"; $scope.userData = users; }); 

My angular app.js is in the static directory and all others(models, routes...) exist in other directories in the root node app. 我的角度app.js在静态目录中,所有其他(模型,路线...)在根节点应用程序的其他目录中。

You seem to be using a REST Api as backend. 您似乎正在使用REST Api作为后端。 So simply you can call the users GET Api from the controller. 因此,您可以简单地从控制器调用用户GET Api。 Something like this. 这样的事情。

$http.get('/api/users/4').then(function(response) { $scope.userData = response.data };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM