我正在为基于 jQuery 的系统编写 AngularJS 应用程序。每个应用程序都需要使用以下代码启动。
如何让它与我的 AngularJS 代码一起工作?
我尝试将整个 Angular 应用程序包含在函数 appStart() 中,但这不起作用。关于如何解决这个问题有什么想法吗?
初始化 JS:
(function () {
function appStart() {
}
function genericError() {
console.error('Something went wrong');
}
TT.native.init()
.done(appStart)
.fail(genericError);
})();
我的 AngularJS 应用程序:
var app = angular.module('myApp', ['ui.sortable', 'ui.router']);
app.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/specs');
$stateProvider
.state('specs', {
url: '/specs',
templateUrl: 'specs.html',
controller: 'SpecsController'
})
.state('editSp...
最佳答案
自从我使用它以来已经很长时间了,但这应该有效。它是 Angular 的手动 Bootstrap ,因此索引文件中没有 ng-app。
(function () {
$(document).ready(function () {
if (TT) {
TT.native.init().done(function () {
angular.bootstrap(document, ['myTickTailApp']);
}).fail(function () {
// Error handling if TickTail fails to init ...
});
} else {
throw new Error('Cannot start app, tt.js not loaded');
}
});
})();
关于javascript - 将 Angular 应用程序包装在 jQuery 函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26236521/