角和混合jQuery UI的 - 为什么不呢? [英] Angular and mixing jQuery UI - Why not?

查看:129
本文介绍了角和混合jQuery UI的 - 为什么不呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code ...

I have the following code...

<div ng-controller="CalendarCtrl">
    <input type="text" ng-model="model.selectedDate" ng-change="onCalendarChange()" id="calendar" />
</div>

<script>
    var app = angular.module("myApp", []);

    app.controller("CalendarCtrl", function($scope) {
        var currentDate = new Date();
        $scope.model = { selectedDate: (currentDate.getMonth() + 1) + "/" + currentDate.getDay() + "/" + currentDate.getFullYear() };
        console.log($scope.model);

        $scope.onCalendarChange = function() {
            console.log(currentDate);
        };
    });

    $(document).ready(function() {
        $("#calendar").datepicker();
    });
</script>

这code看起来做工精美。更改事件被调用并正确显示新selectedDate。

This code appears to work beautifully. The change event is being called and the new selectedDate is displayed correctly.

不过,我总是看到,开发人员正在使用各种箍(主要是指令)来获得的日期选择在角工作职位。

Yet I keep seeing posts where developers are using all kinds of hoops (mainly directives) to get the datepicker to work in Angular.

我失去了一些东西在这里?

Am I missing something here?

推荐答案

使用jQuery像这意味着你是不是声明前pressing你的应用程序不会在这是一种角点的HTML。

Using JQuery like this means that you are not declaratively expressing what your app does in the HTML which is kind of the point of Angular.

从角主页:

AngularJS让您为您的应用程序扩展HTML的词汇。由此产生的环境显得格外前pressive,可读性和快速发展。

AngularJS lets you extend HTML vocabulary for your application. The resulting environment is extraordinarily expressive, readable, and quick to develop.

您也将遇到很多麻烦打倒code道路像

Your also going to run into a lot of trouble down the road with code like

$(document).ready(function() { $("#calendar").datepicker(); });

由于角有当这已完成或已更改的内容不知道。如果你开始使用这样的东西,你也需要有多脏检查,并在角消化周期工作的深入理解。

As Angular has no idea when this has finished or what has changed. If you start using stuff like this you well need a strong understanding of how dirty checking and the digest cycle work in Angular.

您日期选择器不能播放与其他指令漂亮无论是。例如,如果你把这个在 NG-如果和隐藏和显示它,然后日期选择器不会在那里了。

Your date picker won't play nice with other directives either. For example if you put this in an ng-if and hide and show it then the date picker will not be there anymore.

你有没有看着像角UI引导或的角带。他们都提供了与角开箱的日期选择器。

Have you looked into libraries like Angular UI Bootstrap or Angular Strap. They both provide date pickers that work out of the box with Angular.

这篇关于角和混合jQuery UI的 - 为什么不呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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