简体   繁体   English

Angularjs让控制器工作

[英]Angularjs getting controller to work

What's wrong with this controller/html setup? 这个控制器/ html设置有什么问题?

view1.html: view1.html:

    <!doctype html>
    <html ng-app="myApp" ng-controller="View1Ctrl">
    <head>
        <title>Hello AngularJS</title>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script src="view1.js"></script>

    </head>
    <body>
    <div >
        <p>The content is {{user.content}}</p>
    </div>
    </body>
    </html>

View1.js: View1.js:

'use strict';

angular.module('myApp.view1', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/view1', {
    templateUrl: 'view1/view1.html',
    controller: 'View1Ctrl'
  });
}])

.controller('View1Ctrl', [ function GetAuthToken($scope, $http) {
    $http.get('http://dev.hypr.com/DevAPI/rest/login', {headers: {'API_KEY':'87d2e2c64d9a941f0520653e51eae4935f6a640256f2f85610d0b281fa26a9dd'}}).
    success(function(data) {
        $scope.Auth = data;
    });
},function GetUsers($scope, $http) {
  $http.get('http://dev.hypr.com/DevAPI/rest/uafapp/apps/testorigin/users/5',{headers: {'AUTH_TOKEN': GetAuthToken()}}).
  success(function(data) {
    $scope.user = data;
  });
}]);

It keeps giving this error: 它一直给出这个错误:

[Mon May 30 2016 13:11:01 GMT-0400 (Eastern Daylight Time)] "GET     /view1/view1.js" Error (404): "Not found"

Here's the path structure: Path structure 这是路径结构: 路径结构

I am going to suggest something which may not entirely solve your exact problem but it may actually help kick start your own angular development. 我将提出一些可能无法完全解决您确切问题的建议但实际上可能有助于启动您自己的角度开发。

Now my experience comes from writing applications for one of the biggest blue chip companies and it relied heavily on interacting over a RESTful service. 现在我的经验来自于为一家最大的蓝筹公司编写应用程序,并且它非常依赖于通过RESTful服务进行交互。

I find it can be difficult to sometimes build up a structure with new frameworks and from all the research and testing i did i found the easiest way to kickstart development is to use 'HotTowel' which is linked here 我发现有时很难建立一个带有新框架的结构,而且从我所做的所有研究和测试中我发现,最简单的kickstart开发方法是使用链接在这里的 'HotTowel'

It will create the basic structure for your app, auto wire up controllers/views and comes with an example controller + view and routing. 它将为您的应用程序创建基本结构,自动连接控制器/视图,并附带一个示例控制器+视图和路由。

Give it a go as it uses the best practices for writing angular applications. 试一试,因为它使用了编写角度应用程序的最佳实践。

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

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