弹出不在angularjs中工作

时间:2016-05-01 17:43:47

标签: angularjs

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。给出详细信息

1 个答案:

答案 0 :(得分:0)

您正在从文件系统加载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"更改为&#34; https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.js",同样更改为其他文件。
  2. 使用Web服务器在本地托管文件。例如,如果您有python,请转到包含index.html的文件夹,然后运行python -m SimpleHTTPServer(Python 2)或python -m http.server。然后将浏览器指向http://localhost:8000。这将为相对引用的文件提供http:的默认方案,并将从CDN加载它们。
  3. 后者是首选方式。