简体   繁体   English

Angular Js RouteProvider

[英]Angular Js RouteProvider

I am using $routeProvider service in my angular js but problem is on templateURl it provides me error 我在我的有角js中使用$ routeProvider服务,但问题在templateURl上,它为我提供了错误

from server here is the error what i received 从服务器这里是我收到的错误

Failed to load resource: the server responded with a status of 500 (Internal Server Error) angular.js:11594 Error: [$compile:tpload] Failed to load template: /Testing/TestCompleted 无法加载资源:服务器响应状态为500(内部服务器错误)angular.js:11594错误:[$ compile:tpload]无法加载模板:/ Testing / TestCompleted

and here is my angular code for app.js 这是我的app.js角度代码

var app = angular.module('app', ['ngRoute']);
app.controller('CreateController', CreateController);
app.config(function ($routeProvider) {
    $routeProvider
    .when('/',
    {
        templateUrl: "/Testing/TestCompleted",
        controller:"AppCtrl"
    })
});
app.controller("AppCtrl",function ($scope) {
    $scope.newmodel = {

    }
});

我发现视图仅由服务器通过使用路由返回的解决方案,我们只能获取html视图,而不能获取cshtml,因为在调用action时提供了该视图。

The url is giving a ERROR 500. This is that there is something wrong in de code of the page. 网址给出了错误500。这是页面的代码出了点问题。 Please attach your debugger and go to the url "/Testing/TestCompleted" with a browser and check what is wrong. 请附加您的调试器,并使用浏览器转到网址“ / Testing / TestCompleted”,然后检查出什么问题了。

Edit: 编辑:

If the url is really the right one. 如果该网址确实是正确的网址。 Please try the following: 请尝试以下操作:

angular.module('app', ['ngRoute'])
  .controller("AppCtrl",function ($scope) {
    $scope.newmodel = {}
  })
  .config(function ($routeProvider) {
    $routeProvider
    .when('/',
    {
        templateUrl: "/Testing/TestCompleted",
        controller:"AppCtrl"
    })
});

So that the controller is registerd before you do your config as in the example from Angular ( https://docs.angularjs.org/api/ngRoute/service/ $route). 以便在进行配置之前先注册控制器,如Angular( https://docs.angularjs.org/api/ngRoute/service/ $ route)中的示例所示。

The address of the template is likely wrong. 模板的地址可能有误。 I never had to use a format such as '/....' . 我从来没有使用过'/ ....'这样的格式。 You probably want 'Testing/TestCompleted' if the directory Testing is at the root of your project (or './Testing/TestCompleted' both should work). 如果目录“ Testing”位于项目的根目录(或“ ./Testing/TestCompleted”都应工作),则可能需要“ Testing / TestCompleted”。

EDIT: 编辑:

In any case you are probably using an html file for the template, with an extension .html . 无论如何,您可能都使用html文件作为模板,扩展名为.html。 So use 'Testing/TestCompleted.html' for instance. 因此,例如使用“ Testing / TestCompleted.html”。

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

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