只用路由的目的AngularJS [英] Use AngularJS just for routing purposes

查看:110
本文介绍了只用路由的目的AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚被分配了与jQuery的完全由一个网站。它异步加载了几页,想做个SPA。

I've just been assigned a website that was made entirely with jQuery. It load asynchronously a few pages, and want to be a SPA.

现在唯一的事情是,开发商没有想到一般的URL,人们无法通过www.example.com

Now the only thing is that the developer didn't think about URL in general, and people can't access the site any other way than by www.example.com

我知道AngularJS了一下,我的问题是:
-is值得整合AngularJS只是管理路由,只是让我不必去通过jQuery和检查每一个点击,那么每一个环节?

I know AngularJS a bit and my question would be: -Is it worth integrating AngularJS to just manage the routing, just so I don't have to go through jQuery and checking each and every click, then each links?

感谢

推荐答案

当然你也可以使用AngularJs只是路由。

Of course you can use AngularJs for just routing.

在哪里角和jQuery停止工作在一起就是你对角指令产生的观点不能使用jQuery的选择,因为jQuery不要选择运行时生成的意见。

Where angular and jquery stop working together is, you cant use jquery selection on views generated in angular directives, because jquery do not select the runtime generated views.

要监视angularjs当它完成了DOM操作,使用在你的角度控制器来调用 jqueryStartWork 方法,它应该引发jQuery的工作。

To monitor for angularjs to when it finishes the DOM manipulation, use this in your controller of angular to call the jqueryStartWork method, which should initiate working of jquery.

function stuffController($scope) {
$scope.$on('$viewContentLoaded', jqueryStartWork);
}

对于一些angularjs指令渲染显示器,你可以有一个指令时的角度完成由指令DOM操作,这将触发事件。
例如监视NG-重复,渲染完成添加此指令

For some angularjs directives rendering monitor,you can have a directive which will trigger event when the angular finishes dom manipulation by that directive. For example to monitor the ng-repeat, for rendering finish add this directive

var app = angular.module('myapp', [])
.directive('onFinishRender', function ($timeout) {
return {
    restrict: 'A',
    link: function (scope, element, attr) {
        if (scope.$last === true) {
            $timeout(function () {
                scope.$emit('ngRepeatFinished');
            });
        }
    }
}
});

,然后添加一个新功能的控制器,将在NG-重复完成调用,是这样的。

and then add a new function in controller which will be called on ng-repeat finishes, like this.

$scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
    //you also get the actual event object
    //do stuff, execute functions -- whatever...
    alert("ng-repeat finished");
});

但不要忘了这个指令添加到您的NG-repeat标签,像这样

but dont forget to add this directive to your ng-repeat tag, like this

<tr data-ng-repeat="product in products" on-finish-render>


今天,我一直试图在MD-片的一个div运行一个简单D3 SVG追加脚本。我所面临的问题,把它画在控制器完成后(MD-标签也已完成)呈现的一切。我拿出,如果你使用$超时的(上windows.setTimeout包装)的它会在新的事件添加到浏览器的事件队列。它将当前队列(渲染)后运行,并且你为了添加新的超时事件功能(S)之前。它将与0毫秒工作过。

Today I have been trying to run a simple D3 svg append script in a div of a md-tab. I faced the problem to draw it after the controller has finished (md-tab has also finished) rendering everything. I come up that if you use the $timeout (wrapper on windows.setTimeout) it will add a new event to browser's event queue. It will run after current queue(rendering) and before the new timeout event function(s) you add in order. It will work with 0ms too.

 $timeout(drawTree, 0); //drawTree is a function to get #tree div in a md-tab and append a D3 svg

这篇关于只用路由的目的AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆