Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度控制器未在XAMPP web服务上注册_Angularjs_Xampp - Fatal编程技术网

Angularjs 角度控制器未在XAMPP web服务上注册

Angularjs 角度控制器未在XAMPP web服务上注册,angularjs,xampp,Angularjs,Xampp,我得到了这个错误:$controller:ctrlreg这个名字的控制器没有注册。我的所有脚本都已加载,我将它们全部添加到index.html中 我的控制器: (function() { angular.module("nsoftModule").controller("nsoftController", ["nsoftService", function(nsoftService) { var self = this; self.service =

我得到了这个错误:$controller:ctrlreg这个名字的控制器没有注册。我的所有脚本都已加载,我将它们全部添加到index.html中

我的控制器:

 (function() {
    angular.module("nsoftModule").controller("nsoftController", ["nsoftService", function(nsoftService) {
        var self = this;
        self.service = nsoftService;
    }])
})();
我的指示:

 (function() {
    var weatherMod = angular.module("nsoftModule", []);
    weatherMod.directive("nsoftDirective", function() {
        return {
            templateUrl: "Template/weatherTemplate.html",
            controller: "nsoftController as nsoftCtrl"
        }
    });
 })();
我的服务:

 (function() {
    var weatherMod = angular.module("nsoftModule", []);
    weatherMod.service("nsoftService", ["http", function(http) {
        var service = this;
    }]);
})();
我的模块:

(function() {
    var weatherMod = angular.module("nsoftModule", []);
})();
我的模板:

<div class="container">
   <div ng-controller="nsoftController">
      <p>Name : <input type="text" ng-model="name"></p>
      <h1>Hello {{name}}</h1>
   </div>
</div>
和my index.html:

<!DOCTYPE html>
<html ng-app="nsoftApp">
   <head>
      <title>Nsoft App</title>
   </head>
   <body>
      <nsoft-directive></nsoft-directive>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
      <script src="weatherModule.js"></script>
      <script src="Service/weatherService.js"></script>
      <script src="Controller/weatherController.js"></script>
      <script src="Directive/weatherDirective.js"></script>
      <script src="app.js"></script>
   </body>
</html>

Nsoft应用程序

只需删除全局变量,因为在中,您使用的匿名自调用函数变量仅限于一个匿名函数。像他的一样使用

(function() {
    angular.module("nsoftModule").controller("nsoftController", ["nsoftService", function(nsoftService) {
        var self = this;
        self.service = nsoftService;
    }])
})();

(function() {
    angular.module("nsoftModule").directive("nsoftDirective", function() {
        return {
            templateUrl: "Template/weatherTemplate.html",
            controller: "nsoftController as nsoftCtrl"
        }
    });
})();

//change http to $http 
(function() {
    angular.module("nsoftModule").service("nsoftService", ["$http", function($http) {
        var service = this;
    }]);
})();

(function() {
    angular.module("nsoftModule", []);
})();
由于控制器从指令分配,因此也不需要在html中声明它

<div class="container">
<div >
   <p>Name : <input type="text" ng-model="nsoftCtrl.name"></p>
   <h1>Hello {{nsoftCtrl.name}}</h1>
</div>

(function() {
    angular.module("nsoftApp", ["nsoftModule"]);
})();

姓名:

你好{{nsoftCtrl.name} (功能(){ angular.module(“nsoftApp”、[“nsoftModule”]); })();
非常感谢您的回答Sachila,但即使您进行了改进,我仍然会遇到相同的错误…请检查此项。我会更新答案,欢迎您。别忘了投票并标上答案
<div class="container">
<div >
   <p>Name : <input type="text" ng-model="nsoftCtrl.name"></p>
   <h1>Hello {{nsoftCtrl.name}}</h1>
</div>

(function() {
    angular.module("nsoftApp", ["nsoftModule"]);
})();