Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.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
Javascript 外部文件中的角度不工作_Javascript_Asp.net_Angularjs - Fatal编程技术网

Javascript 外部文件中的角度不工作

Javascript 外部文件中的角度不工作,javascript,asp.net,angularjs,Javascript,Asp.net,Angularjs,为了便于理解,我举了两个例子,一个有效,另一个无效 第一个是html页面中的脚本内容,它工作正常 <html ng-app> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

为了便于理解,我举了两个例子,一个有效,另一个无效

第一个是html页面中的脚本内容,它工作正常

        <html ng-app>
          <head>
              <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
          </head>
          <body>
            <input type="text" ng-model="helloAngular" />
            <h1>{{helloAngular}}</h1>
          </body>
        </html>
编译后看起来是这样的:

javascript文件正确地包含在html中(我尝试了$(document.ready())。当然,对于第二个示例,我从html标记中删除了ng app属性

还尝试清除Cookie和缓存,但没有成功。在其他浏览器中也会发生同样的事情

我在其他应用程序功能中使用了这个角度文件,它们都不再工作了。当我打开文件并将新控制器添加到现有应用程序模块时,它停止工作。当然,我在新的.js文件中尝试了上面的示例,还尝试注释掉前面提到的angular文件中的所有angular代码

编辑1。

好的,我在html中内联复制/粘贴了angular代码,但仍然不走运

        <script type="text/javascript">
            angular.module("app", []).controller("personController", [$scope, function ($scope) {
                $scope.firstName = "John";
                $scope.lastName = "Doe";
            }]);
        </script>


        <div ng-app="app">
            <p>Try to change the names.</p>
            <div ng-controller="personController">
                <p>
                    First Name:
                    <input type="text" ng-model="firstName" />
                </p>
                <p>
                    Last Name:
                    <input type="text" ng-model="lastName" />
                </p>
                <p>
                    Full Name:
                    {{firstName}} {{lastName}}
                </p>
            </div>
        </div>

角度.module(“app”、[]).controller(“personController”、[$scope、function($scope){
$scope.firstName=“John”;
$scope.lastName=“Doe”;
}]);
尝试更改名称

名字:

姓氏:

全名: {{firstName}}{{lastName}}

使用@BarouchKandov plunker项目,我重新创建了这个问题,它在plunker项目下工作,但同一段代码在我的ASP.NET项目中不工作


我也尝试过删除[$scope,…]括号

你能提供任何链接而不是代码片段吗?你的控制器没有正确加载,因此控制器中的更改没有反映在视图中。我用你的两个例子创建了一个plunker项目:谢谢大家的帮助,但仍然没有运气。请检查后编辑。我将angular代码插入到内联脚本标记中,但它仍然不起作用。它似乎无法识别模块和控制器
angular.module("app", []).controller("personController", function ($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
});
        <script type="text/javascript">
            angular.module("app", []).controller("personController", [$scope, function ($scope) {
                $scope.firstName = "John";
                $scope.lastName = "Doe";
            }]);
        </script>


        <div ng-app="app">
            <p>Try to change the names.</p>
            <div ng-controller="personController">
                <p>
                    First Name:
                    <input type="text" ng-model="firstName" />
                </p>
                <p>
                    Last Name:
                    <input type="text" ng-model="lastName" />
                </p>
                <p>
                    Full Name:
                    {{firstName}} {{lastName}}
                </p>
            </div>
        </div>