第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AngularJS + JQuery:如何在angularjs中使用動態(tài)內(nèi)容

AngularJS + JQuery:如何在angularjs中使用動態(tài)內(nèi)容

繁星點點滴滴 2019-07-30 14:10:07
AngularJS + JQuery:如何在angularjs中使用動態(tài)內(nèi)容我正在使用jQuery和AngularJS開發(fā)Ajax應(yīng)用程序。當(dāng)我使用jQuery的html函數(shù)更新div的內(nèi)容(包含AngularJS綁定)時,AngularJS綁定不起作用。以下是我要做的代碼:$(document).ready(function() {   $("#refreshButton").click(function() {     $("#dynamicContent").html("<button ng-click='count = count + 1' ng-init='count=0'>Increment</button><span>count: {{count}} </span>")   });});</style><script src="http://docs.angularjs.org/angular-1.0.1.min.js"></script><style>.ng-invalid {   border: 1px solid red;}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><div ng-app="">   <div id='dynamicContent'>     <button ng-click="count = count + 1" ng-init="count=0">         Increment      </button>     <span>count: {{count}} </span>   </div>   <button id='refreshButton'>     Refresh  </button></div>我在帶有ID的div中有動態(tài)內(nèi)容#dynamicContent,并且我有一個刷新按鈕,可以在單擊刷新時更新此div的內(nèi)容。如果我不刷新內(nèi)容,增量將按預(yù)期工作,但在刷新后,AngularJS綁定將停止工作。這可能在AngularJS中無效,但我最初使用jQuery構(gòu)建應(yīng)用程序并稍后開始使用AngularJS,因此我無法將所有內(nèi)容遷移到AngularJS。任何有關(guān)在AngularJS中工作的幫助都非常感謝。
查看完整描述

3 回答

?
白板的微信

TA貢獻(xiàn)1883條經(jīng)驗 獲得超3個贊

因為angular.element(document).injector()給出了錯誤injector is not defined 所以,我創(chuàng)建了一個可以在AJAX調(diào)用之后運(yùn)行的函數(shù)或者使用jQuery更改DOM的函數(shù)。

  function compileAngularElement( elSelector) {

        var elSelector = (typeof elSelector == 'string') ? elSelector : null ;  
            // The new element to be added
        if (elSelector != null ) {
            var $div = $( elSelector );

                // The parent of the new element
                var $target = $("[ng-app]");

              angular.element($target).injector().invoke(['$compile', function ($compile) {
                        var $scope = angular.element($target).scope();
                        $compile($div)($scope);
                        // Finally, refresh the watch expressions in the new element
                        $scope.$apply();
                    }]);
            }

        }

通過傳遞新元素的選擇器來使用它。像這樣

compileAngularElement( '.user' ) ;


查看完整回答
反對 回復(fù) 2019-07-30
  • 3 回答
  • 0 關(guān)注
  • 774 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號