简体   繁体   English

Angular找不到我的控制器

[英]Angular could not find my controller

In my app I'm trying to pass the Id value to my controller like this: 在我的应用中,我试图像这样将Id值传递给控制器​​:

http://localhost:29045/visitorMain/?Id=afef8e80-0864-e411-8865-000c295e296b

But I am getting a "The resource cannot be found" error. 但是我收到“找不到资源”错误。

Here is my code below: app.js 这是我的代码如下:app.js

 'use strict'; var app = angular.module('loginApp', ['ngRoute']); app.config(['$routeProvider', function($routeProvider) { $routeProvider.when('/login', { templateUrl: 'partials/login.html', controller: 'loginController' }); $routeProvider.when('/visitorMain/:Id', { templateUrl: 'partials/visitorMain.html', controller: 'visitorController' }); $routeProvider.otherwise({ redirectTo: '/login' }); } ]); 

visitorController.js visitorController.js

 'use strict'; app.controller('visitorController', function($scope, $routeParams) { //console.log(Id); //console.log(UserName); // $scope.login = function (user) { // loginService.login(user); // } }); 

Calling My visitorController 呼叫我的visitorController

  $http.get('/visitorMain/', { params: { Id: "someid" } }); 

Result: 结果: 在此处输入图片说明

Any suggestions? 有什么建议么?

You have uncorrect url. 您的网址不正确。 Your controller should be like this: 您的控制器应如下所示:

     $http.get('/visitorMain', {
   params: {
     Id: "someid"
   }
 });

So your url will be: http://localhost:29045/visitorMain?Id=afef8e80-0864-e411-8865-000c295e296b . 所以您的网址将是: http:// localhost:29045 / visitorMain?Id = afef8e80-0864-e411-8865-000c295e296b

You are forgetting the hashtag. 您忘记了标签。 Try 尝试

$http.get('/#/visitorMain/', {
   params: {
     Id: "someid"
   }
 });

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

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