【问题标题】:pop up is not working in angularjs弹出在angularjs中不起作用
【发布时间】:2025-12-17 06:50:01
【问题描述】:
index.html
html ng-app="myapp">
<head>
    <title>kanna</title>
    <meta charset="UTF-8">

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.4.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body ng-controller="Ctrl">
    <label>NAME</label>
    <input type="text"  ng-model="name">
    <label>AGE</label>
    <input type="text" ng-model="age">
    <button ng-click="create()">swathi</button>
</body>
</html>

app.js:

var app=angular.module('myapp',['ui.bootstrap']);
app.controller("Ctrl",['$scope','$modal',function($scope,$modal){
    $scope.create=function(){
        var modalInstance=$modal.open({
            templateUrl:'page.html',
        })
    }
}
    ])

三个错误来了是: file://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.js 加载资源失败:net::ERR_FILE_NOT_FOUND file://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css 加载资源失败:net::ERR_FILE_NOT_FOUND file://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.4.js 加载资源失败:net::ERR_FILE_NOT_FOUND 找到解决方案并回复。完整的细节以及如何设置js文件和css。给出详细信息

【问题讨论】:

  • 这意味着你的 angularjs 引用没有加载

标签: angularjs


【解决方案1】:

您正在从文件系统加载index.html(通过双击文件资源管理器中的文件?)。

这为 HTML 页面内的相对引用提供了默认方案file:

因此,当您尝试包含文件 "//ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.js" 时,它会尝试查找 file://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.js

有几种方法可以解决这个问题:

  1. 将默认方案更改为https:// 以改为从CDN 加载文件。因此,将"//ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.js" 更改为“https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.js"”,其他文件也是如此。
  2. 使用网络服务器在本地托管文件。例如,如果您有python,请转到具有index.html 的文件夹,然后运行python -m SimpleHTTPServer (Python 2) 或python -m http.server。然后将您的浏览器指向http://localhost:8000。这将为相对引用的文件提供http: 的默认方案,并将从 CDN 加载它们。

后者是首选方式。

【讨论】: