javascript - 为什么 angular.bootstrap 代码不适用于 AngularJS V1.6 之前的版本?

标签 javascript angularjs angularjs-1.6

我的问题是,当我包含 URL 时:http://code.angularjs.org/snapshot/angular.js 在下面<script>标签代码工作得很好, 相反,如果我使用此 URL:https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js , angular 没有加载/引导 为什么?

<!doctype html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
    <script type="text/javascript" src="Program6.js"></script>
</head>
<body>
    <div>
        <input type="text" ng-model="sampledata" />
        <p>{{ sampledata }}</p>
    </div>
</body>
</html>

我的 JS 代码以防它有助于解决问题:

angular.module('myApp', []);
angular.element(function() {
    angular.bootstrap(document, ['myApp']);
});

最佳答案

对于 AngularJS 1.6+ 使用:

angular.module('myApp', []);
angular.element(function() {
    angular.bootstrap(document, ['myApp']);
});

对于旧版本的 AngularJS 使用:

angular.module('myApp', []);
angular.element(document).ready(function() {
    angular.bootstrap(document, ['myApp']);
});

来自文档:

  • ready() (deprecated, use angular.element(callback) instead of angular.element(document).ready(callback))

— AngularJS angular.element API Reference

有关详细信息,请参阅,

关于javascript - 为什么 angular.bootstrap 代码不适用于 AngularJS V1.6 之前的版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44057395/

相关文章:

javascript - AngularJS 的路由问题

javascript - jQuery 自定义内容滚动条遍历路径样式 :)

javascript - 如何在 RegEx 中分割可选参数?

javascript - 使用拦截器处理 Ionic App 中的离线数据

angularjs - 在基于 AngularJS 的 Web 应用程序中使用 Selenium

angularjs - 使用 yeoman 设置的 AngularJS 项目的路由问题

javascript - ol.Overlay 在 IE 和 Firefox 上滚动 map

javascript - 我该怎么做 "A Datepicker with 3 separate input one for month , day and year and validate it"?

angularjs - 在 AngularJS 中重用 ngClass 指令

javascript - Angular-route1.6.1 无法正常工作