Ember.js load jquery on template render (no refresh) - javascript

I have created an ember.js template (about.hbs). I want to run some jQuery on the page but the jQuery only works if I reload the page.
I don't really get where I am meant to put the jQuery code to make it run when the template is rendered. At them moment I have put it in the controller.
App.AboutController = Ember.ObjectController.extend({
$(document).ready(function() {
//my jquery code
});
});
Could someone help me out?

You are going to want to lifecycle callbacks (see Ember docs). When a template is rendered Ember will trigger the didInsertElement callback. You can simply add your own code to this function, and if you want to use any jQuery inside of that callback you must keep the scope in mind: this.$()
Your code will look like this:
didInsertElement: function(){
this.$() //jquery code
}

Related

JsTree is not applied on a later built list

I have an Angular2 web application which loads a ul/li-list from a remote JSON object when a button is clicked.
The generated div and list looks like this:
<div class="jstree jstree-1 jstree-default jstree-leaf" role="tree" aria-multiselectable="true" tabindex="0" aria-activedescendant="j1_loading" aria-busy="false" ng-reflect-inner-h-t-m-l="<ul class=".actual"><li>Windows<ul><li>setupact.log</li><li>Tasks<ul><li>SCHEDLGU.TXT</li></ul></li><li>Logs<ul><li>CBS<ul><li>CBS.log</li></ul></li><li>DPX<ul><li>setupact.log</li></ul></li></ul></li><li>AppCompat<ul><li>Programs<ul><li>AEINV_PREVIOUS.xml</li><li>RecentFileCache.bcf</li><li>AEINV_WER_{91399519-4D7E-4F2D-8E40-5C55523C2307}_20160914_210543.xml</li></ul></li></ul></li><li>winsxs<ul><li>ManifestCache<ul><li>702349c5b78f9a04_blobs.bin</li></ul></li><li>poqexec.log</li></ul></li><li>rescache<ul><li>ResCache.mni</li></ul></li><li>System32<ul><li>Microsoft<ul><li>Protect<ul><li>S-1-5-19<ul><li>Preferred</li></ul></li></ul></li></ul></li><li>7B296FB0-376B-497e-B012-9C450E1B7327-5P-1.C7483456-A289-439d-8115-601632D005A0</li><li>winevt<ul><li>Logs<ul><li>Security.evtx</li><li>Microsoft-Windows-Windows Firewall With Advanced Security%4Firewall.evtx</li><li>Windows PowerShell.evtx</li><li>Microsoft-Windows-Dhcpv6-Client%4Admin.evtx</li><li>System.evtx</li><li>Microsoft-Windows-Application-Experience%4Program-Telemetry.evtx</li><li>Microsoft-Windows-Kernel-WHEA%4Operational.evtx</li><li>Microsoft-Windows-Resource-Exhaustion-Detector%4Operational.evtx</li><li>Microsoft-Windows-NetworkLocationWizard%4Operational.evtx</li><li>Microsoft-Windows-LanguagePackSetup%4Operational.evtx</li><li>Microsoft-Windows-OfflineFiles%4Operational.evtx</li><li>Microsoft-Windows-WindowsBackup%4ActionCenter.evtx</li><li>Microsoft-Windows-International%4Operational.evtx</li><li>Microsoft-Windows-WindowsUpdateClient%4Operational.evtx</li><li>Microsoft-Windows-MUI%4Operational.evtx</li><li>Microsoft-Windows-Diagnostics-Performance%4Operational.evtx</li><li>Microsoft-Windows-Compat-Appraiser%4Operational.evtx</li><li>Microsoft-Windows-Diagnosis-DPS%4Operational.evtx</li><li>Application.evtx</li><li>Microsoft-Windows-BranchCacheSMB%4Operational.evtx</li><li>Microsoft-Windows-Bits-Client%4Operational.evtx</li><li>Microsoft-Windows-GroupPolicy%4Operational.evtx</li><li>Microsoft-Windows-Windows Defender%4Operational.evtx</li><li>Microsoft-Windows-Known Folders API Service.evtx</li><li>Microsoft-Windows-Windows Defender%4WHC.evtx</li><li>Microsoft-Windows-HomeGroup Provider Service%4Operational.evtx</li><li>Microsoft-Windows-ReliabilityAnalysisComponent%4Operational.evtx</li><li>Microsoft-Windows-CodeIntegrity%4Operational.evtx</li><li>Microsoft-Windows-TerminalServices-RemoteConnectionManager%4Operational.evtx</li><li>Microsoft-Windows-User Profile Service%4Operational.evtx</li><li>Microsoft-Windows-WinRM%4Operational.evtx</li><li>Microsoft-Windows-NetworkProfile%4Operational.evtx</li><li>Microsoft-Windows-Application-Experience%4Program-Inventory.evtx</li><li>Microsoft-Windows-TerminalServices-LocalSessionManager%4Operational.evtx</li><li>Setup.evtx</li><li>Microsoft-Windows-CAPI2%4Operational.evtx</li></ul></li></ul></li><li>7B296FB0-376B-497e-B012-9C450E1B7327-5P-0.C7483456-A289-439d-8115-601632D005A0</li><li>wdi<ul><li>{86432a0b-3c7d-4ddf-a89c-172faa90485d}<ul><li>S-1-5-21-1426688081-248760799-3800414735-1001_UserData.bin</li></ul></li><li>ShutdownPerformanceDiagnostics_SystemData.bin</li><li>BootPerformanceDiagnostics_SystemData.bin</li><li>LogFiles<ul><li>WdiContextLog.etl.003</li><li>WdiContextLog.etl.002</li><li>WdiContextLog.etl.001</li><li>BootCKCL.etl</li><li>ShutdownCKCL.etl</li></ul></li></ul></li><li>LogFiles<ul><li>Scm<ul><li>a1cfa52f-06f2-418d-addb-cd6456d66f43</li><li>2c59ecaf-3a27-4640-9f4b-519b05bdd70f</li><li>5b184694-64c3-4633-94c5-945b3fa561d6</li><li>6b7ac694-8d6d-481b-9dd8-2a3a741ada6d</li><li>956981f2-9434-4ac7-92d1-255484e54e4d</li><li>bba67ad0-4ba0-4b44-827b-ff419b70c057</li><li>b9bee219-c29e-4310-819c-147a5a0e045e</li><li>731e9c62-95b5-4c8c-ab64-4cc591c9ff5b</li><li>9334c323-f100-4656-9ba0-e4aa69c0f9c2</li><li>d21f6024-191f-4454-bbbc-09a650da2549</li><li>a316e645-1c56-45a6-bd6a-7dca79778090</li><li>a6394592-54ce-4e93-8d64-1a068f462632</li><li>f1369a11-e983-4458-b390-712efa1cba44</li><li>38279e40-3dc1-4c28-a688-148aed61ff69</li><li>1ec9510d-a439-4950-9399-b6399edf9ea7</li><li>de8bae53-2809-4f75-85ef-427d364b9b2c</li><li>9b75c702-ea13-406a-badb-6c588ee4375b</li><li>de8699d2-8a05-42f7-8a85-5162af47d26a</li></ul></li><li>WMI<ul><li>RtBackup<ul><li>EtwRTDiagLog.etl</li><li>EtwRTEventLog-Application.etl</li><li>EtwRTEventLog-System.etl</li></ul></li></ul></li></ul></li><li>spool<ul><li>drivers<ul><li>w32x86<ul><li>3<ul><li>mxdwdui.BUD</li></ul></li><li>PCC<ul><li>tsprint.inf_x86_neutral_c48d421ad2c1e3e3.cab</li></ul></li></ul></li></ul></li></ul></li><li>Tasks<ul><li>Microsoft<ul><li>Windows Defender<ul><li>MP Scheduled Scan</li></ul></li></ul></li></ul></li><li>DriverStore<ul><li>INFCACHE.1</li><li>FileRepository<ul><li>prnep00l.inf_x86_neutral_3323920c1a72a42d<ul><li>prnep00l.PNF</li></ul></li><li>prnbr009.inf_x86_neutral_3f6b69c8d1091fd8<ul><li>prnbr009.PNF</li></ul></li><li>prnkm002.inf_x86_neutral_ded1a36701bddc86<ul><li>prnkm002.PNF</li></ul></li><li>prnca003.inf_x86_neutral_f0a023edfd5cd833<ul><li>prnca003.PNF</li></ul></li><li>prnca00d.inf_x86_neutral_8883e3ab4a33bfbb<ul><li>prnca00d.PNF</li></ul></li><li>prnbr006.inf_x86_neutral_331a0c6df1c9d3e1<ul><li>prnbr006.PNF</li></ul></li><li>prnep004.inf_x86_neutral_25623e649d146f5d<ul><li>prnep004.PNF</li></ul></li><li>prnkm003.inf_x86_neutral_ea465b3729b37f54<ul><li>prnkm003.PNF</li></ul></li><li>prnbr005.inf_x86_neutral_407befecac90c7f1<ul><li>prnbr005.PNF</li></ul></li><li>prnrc003.inf_x86_neutral_e9198ff5f961d947<ul><li>prnrc003.PNF</li></ul></li><li>bth.inf_x86_neutral_a6bf6d613b46f6a5<ul><li>bth.PNF</li></ul></li><li>prnin004.inf_x86_neutral_2aba7beb4ab9a9e8<ul><li>prnin004.PNF</li></ul></li><li>prnnr004.inf_x86_neutral_15e7dc89d102e928<ul><li>prnnr004.PNF</li></ul></li><li>prnin002.inf_x86_neutral_b9fa18a8d63d5294<ul><li>prnin002.PNF</li></ul></li><li>prnca00g.inf_x86_neutral_b19defbd7969a7c7<ul><li>prnca00g.PNF</li></ul></li><li>prnhp005.inf_x86_neutral_9307c57b91a7985e<ul><li>prnhp005.PNF</li></ul></li><li>prnrc006.inf_x86_neutral_404ca57b9d9c1e47<ul><li>prnrc006.PNF</li></ul></li><li>amdsata.inf_x86_neutral_5c3d0d1e97e99e10<ul><li>amdsata.PNF</li></ul></li><li>prnrc005.inf_x86_neutral_73b01a2655fdb5c5<ul><li>prnrc005.PNF</li></ul></li><li>prnca00f.inf_x86_neutral_b94365c0e502f290<ul><li>prnca00f.PNF</li></ul></li><li>prnep00a.inf_x86_neutral_d4494950448771ed<ul><li>prnep00a.PNF</li></ul></li><li>prnge001.inf_x86_neutral_51cbe14e4cdde8c2<ul><li>prnge001.PNF</li></ul></li><li>prnkm004.inf_x86_neutral_b456c14d5367f83c<ul><li>prnkm004.PNF</li></ul></li><li>prnbr008.inf_x86_neutral_87aae9d395393afd<ul><li>prnbr008.PNF</li></ul></li><li>prnok002.inf_x86_neutral_436ff5d24333cca0<ul><li>prnok002.PNF</li></ul></li><li>prnin003.inf_x86_neutral_dca922447801904c<ul><li>prnin003.PNF</li></ul></li><li>prnsa002.inf_x86_neutral_db272f9cd17a383f<ul><li>prnsa002.PNF</li></ul></li><li>prnbr007.inf_x86_neutral_af94d26aafd1ca3a<ul><li>prnbr007.PNF</li></ul></li><li>prnep003.inf_x86_neutral_342be98eb74e1449<ul><li>prnep003.PNF</li></ul></li><li>prnep005.inf_x86_neutral_f4a4a2a89cb57323<ul><li>prnep005.PNF</li></ul></li><li>prnrc004.inf_x86_neutral_7d5665e9e43f678d<ul><li>prnrc004.PNF</li></ul></li><li>prnhp003.inf_x86_neutral_8685826a5ca37e6b<ul><li>prnhp003.PNF</li></ul></li><li>iastorv.inf_x86_neutral_0bcee2057afcc090<ul><li>iastorv.PNF</li></ul></li><li>prnca00b.inf_x86_neutral_c675b60dd45218c1<ul><li>prnca00b.PNF</li></ul></li><li>prnrc007.inf_x86_neutral_cfebba21b1c02dd7<ul><li>prnrc007.PNF</li></ul></li><li>prnle003.inf_x86_neutral_a8106f7f3af21d88<ul><li>prnle003.PNF</li></ul></li><li>prnbr002.inf_x86_neutral_1d14699bf2d4d936<ul><li>prnbr002.PNF</li></ul></li><li>prnnr003.inf_x86_neutral_02802729a95f0eed<ul><li>prnnr003.PNF</li></ul></li><li>prnep00c.inf_x86_neutral_92ff44dcbf1c760c<ul><li>prnep00c.PNF</li></ul></li><li>prnsv003.inf_x86_neutral_2011fa0a7f786266<ul><li>prnsv003.PNF</li></ul></li><li>prnnr002.inf_x86_neutral_b9a1c43c0cb6c940<ul><li>prnnr002.PNF</li></ul></li><li>faxcn002.inf_x86_neutral_29a66691dd7a46a5<ul><li>faxcn002.PNF</li></ul></li><li>prnod002.inf_x86_neutral_c36a5fe1ac15a734<ul><li>prnod002.PNF</li></ul></li><li>prnrc00b.inf_x86_neutral_354df7938905aa3b<ul><li>prnrc00b.PNF</li></ul></li><li>prnep00b.inf_x86_neutral_d0e9433101a2df79<ul><li>prnep00b.PNF</li></ul></li><li>prnsv004.inf_x86_neutral_3ee5a15023f3b3ed<ul><li>prnsv004.PNF</li></ul></li><li>prngt002.inf_x86_neutral_a10ecaa46786286d<ul><li>prngt002.PNF</li></ul></li><li>nvraid.inf_x86_neutral_0276fc3b3ea60d41<ul><li>nvraid.PNF</li></ul></li><li>prnbr004.inf_x86_neutral_a976dec554a0be13<ul><li>prnbr004.PNF</li></ul></li><li>prnep002.inf_x86_neutral_9111d9b86cbd3f64<ul><li>prnep002.PNF</li></ul></li><li>prnrc002.inf_x86_neutral_3fb2e6c401a9c7d8<ul><li>prnrc002.PNF</li></ul></li><li>prnbr003.inf_x86_neutral_21c4516754f2bda5<ul><li>prnbr003.PNF</li></ul></li><li>prnle004.inf_x86_neutral_60637fb8287b0bdb<ul><li>prnle004.PNF</li></ul></li><li>prnkm005.inf_x86_neutral_a2013031e279b6f6<ul><li>prnkm005.PNF</li></ul></li><li>prngt004.inf_x86_neutral_f7b569fe96e4f7ae<ul><li>prngt004.PNF</li></ul></li><li>prnhp002.inf_x86_neutral_e6daa9c39ac001a3<ul><li>prnhp002.PNF</li></ul></li><li>prnfx002.inf_x86_neutral_f83f67e1c22e557b<ul><li>prnfx002.PNF</li></ul></li><li>prnhp004.inf_x86_neutral_95288ae6f32f1fe7<ul><li>prnhp004.PNF</li></ul></li></ul></li></ul></li><li>SMI<ul><li>Store<ul><li>Machine<ul><li>SCHEMA.DAT{f74722ed-7b07-11e6-b6ad-0800273c6b02}.TM.blf</li><li>SCHEMA.DAT.LOG1</li><li>SCHEMA.DAT{f74722ed-7b07-11e6-b6ad-0800273c6b02}.TMContainer00000000000000000001.regtrans-ms</li><li>SCHEMA.DAT</li></ul></li></ul></li></ul></li><li>CodeIntegrity<ul><li>bootcat.cache</li></ul></li><li>wbem<ul><li>Repository<ul><li>MAPPING1.MAP</li><li>MAPPING2.MAP</li><li>MAPPING3.MAP</li><li>OBJECTS.DATA</li><li>INDEX.BTR</li></ul></li></ul></li><li>wfp<ul><li>wfpdiag.etl</li></ul></li><li>config<ul><li>SOFTWARE.LOG1</li><li>SECURITY.LOG1</li><li>SAM</li><li>DEFAULT.LOG1</li><li>COMPONENTS.LOG1</li><li>systemprofile<ul><li>AppData<ul><li>LocalLow<ul><li>Microsoft<ul><li>CryptnetUrlCache<ul><li>MetaData<ul><li>7396C420A8E1BC1DA97F1AF0D10BAD21</li><li>57C8EDB95DF3F0AD4EE2DC2B8CFD4157</li><li>37C951188967C8EB88D99893D9D191FE</li><li>21253908F3CB05D51B1C2DA8B681A785</li><li>A1377F7115F1F126A15360369B165211</li><li>F90F18257CBB4D84216AC1E1F3BB2C76</li><li>A583E2A51BFBDC1E492A57B7C8325850</li><li>3130B1871A126520A8C47861EFE3ED4D</li><li>696F3DE637E6DE85B458996D49D759AD</li><li>4C7F163ED126D5C3CB9457F68EC64E9E</li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li><li>SYSTEM</li><li>DEFAULT</li><li>COMPONENTS{6cced2ed-6e01-11de-8bed-001e0bcd1824}.TM.blf</li><li>SAM.LOG1</li><li>SYSTEM.LOG1</li><li>COMPONENTS</li><li>SECURITY</li><li>COMPONENTS{6cced2ed-6e01-11de-8bed-001e0bcd1824}.TMContainer00000000000000000002.regtrans-ms</li><li>COMPONENTS{6cced2ed-6e01-11de-8bed-001e0bcd1824}.TMContainer00000000000000000001.regtrans-ms</li><li>TxR<ul><li>{6cced300-6e01-11de-8bed-001e0bcd1824}.TxR.0.regtrans-ms</li><li>{6cced300-6e01-11de-8bed-001e0bcd1824}.TxR.2.regtrans-ms</li><li>{6cced300-6e01-11de-8bed-001e0bcd1824}.TxR.blf</li><li>{6cced301-6e01-11de-8bed-001e0bcd1824}.TM.blf</li><li>{6cced301-6e01-11de-8bed-001e0bcd1824}.TMContainer00000000000000000001.regtrans-ms</li></ul></li><li>SOFTWARE</li></ul></li><li>NetworkList<ul><li>Icons<ul><li>{1ED31542-AA58-4CD5-A56A-B9007AB965C3}_16.bin</li><li>{1ED31542-AA58-4CD5-A56A-B9007AB965C3}_24.bin</li><li>{1ED31542-AA58-4CD5-A56A-B9007AB965C3}_48.bin</li><li>{1ED31542-AA58-4CD5-A56A-B9007AB965C3}_32.bin</li></ul></li></ul></li><li>catroot2<ul><li>{F750E6C3-38EE-11D1-85E5-00C04FC295EE}<ul><li>catdb</li></ul></li><li>{127D0A1D-4EF2-11D1-8608-00C04FC295EE}<ul><li>catdb</li></ul></li><li>edb.log</li><li>edb004E5.log</li><li>edb.chk</li><li>edb004E4.log</li></ul></li></ul></li><li>SoftwareDistribution<ul><li>DataStore<ul><li>DataStore.edb</li><li>Logs<ul><li>edb.chk</li><li>edb.log</li></ul></li></ul></li><li>ReportingEvents.log</li></ul></li><li>ServiceProfiles<ul><li>NetworkService<ul><li>NTUSER.DAT.LOG1</li><li>NTUSER.DAT</li><li>AppData<ul><li>Roaming<ul><li>Microsoft<ul><li>SoftwareProtectionPlatform<ul><li>Cache<ul><li>cache.dat</li></ul></li><li>tokens.dat</li></ul></li></ul></li></ul></li><li>Local<ul><li>Microsoft<ul><li>Media Player<ul><li>CurrentDatabase_372.wmdb</li></ul></li></ul></li><li>Temp<ul><li>MpCmdRun.log</li></ul></li></ul></li></ul></li></ul></li><li>LocalService<ul><li>NTUSER.DAT.LOG1</li><li>NTUSER.DAT</li><li>AppData<ul><li>Roaming<ul><li>PeerNetworking<ul><li>idstore.sst</li><li>idstore.sst.new</li></ul></li><li>Microsoft<ul><li>Crypto<ul><li>RSA<ul><li>S-1-5-19<ul><li>7e22207fe9846926e18c29d3e675240e_f98e9ddc-0e1b-4293-b1aa-bc41c96b9f31</li></ul></li></ul></li></ul></li></ul></li></ul></li><li>Local<ul><li>FontCache-S-1-5-21-1426688081-248760799-3800414735-1001.dat</li><li>FontCache-System.dat</li><li>FontCache-FontFace.dat</li></ul></li></ul></li></ul></li></ul></li><li>bootstat.dat</li><li>servicing<ul><li>Sessions<ul><li>Sessions.xml</li><li>Sessions.back.xml</li><li>30543655_539879863.xml</li></ul></li></ul></li><li>Temp<ul><li>MpCmdRun.log</li><li>MpSigStub.log</li></ul></li><li>inf<ul><li>setupapi.ev1</li><li>setupapi.dev.log</li><li>setupapi.app.log</li></ul></li><li>Microsoft.NET<ul><li>Framework<ul><li>v4.0.30319<ul><li>ngen.log</li><li>ngen_service.log</li></ul></li></ul></li></ul></li><li>WindowsUpdate.log</li></ul></li><li>System Volume Information<ul><li>Syscache.hve</li><li>Syscache.hve.LOG1</li><li>{ebac27bb-7b10-11e6-a5bc-0800273c6b02}{3808876b-c176-4e48-b7ae-04046e6cc752}</li></ul></li><li>pagefile.sys</li><li>Users<ul><li>vagrant<ul><li>ntuser.dat.LOG1</li><li>NTUSER.DAT</li><li>AppData<ul><li>LocalLow<ul><li>Microsoft<ul><li>CryptnetUrlCache<ul><li>Content<ul><li>B912B2C6928A18B8CD7D50CF08BEA95B_87708DAABE1AF38B603CEFBE5F2B3276</li></ul></li><li>MetaData<ul><li>EDC238BFF48A31D55A97E1E93892934B_C20E0DA2D0F89FE526E1490F4A2EE5AB</li><li>B912B2C6928A18B8CD7D50CF08BEA95B_87708DAABE1AF38B603CEFBE5F2B3276</li><li>40E450F7CE13419A2CCC2A5445035A0A_97482851B9CF8FBB790FA8AEAB0C772D</li><li>C0018BB1B5834735BFA60CD063B31956</li><li>7396C420A8E1BC1DA97F1AF0D10BAD21</li><li>57C8EDB95DF3F0AD4EE2DC2B8CFD4157</li><li>DCE3BDBF5BDD86E2AB5B471CB90709B4_A7704BF276C97AA4D70879F611AA7DB9</li><li>37C951188967C8EB88D99893D9D191FE</li><li>C46E7B0F942663A1EDC8D9D6D7869173_42820CDFEA41DC84AAB89A6B63561873</li><li>21253908F3CB05D51B1C2DA8B681A785</li><li>FB788E090BC1F3AA2FBC9E8FB2859601</li><li>F90F18257CBB4D84216AC1E1F3BB2C76</li><li>696F3DE637E6DE85B458996D49D759AD</li></ul></li></ul></li></ul></li></ul></li><li>Roaming<ul><li>Microsoft<ul><li>Windows<ul><li>Recent<ul><li>CustomDestinations<ul><li>d93f411851d7c929.customDestinations-ms</li></ul></li><li>AutomaticDestinations<ul><li>7e4dca80246863e3.automaticDestinations-ms</li><li>1b4dd67f29cb1962.automaticDestinations-ms</li></ul></li></ul></li></ul></li></ul></li></ul></li><li>Local<ul><li>Microsoft<ul><li>Windows<ul><li>Explorer<ul><li>thumbcache_256.db</li><li>thumbcache_32.db</li><li>thumbcache_idx.db</li></ul></li><li>Temporary Internet Files<ul><li>counters.dat</li></ul></li><li>WebCache<ul><li>V01.log</li><li>WebCacheV01.dat</li><li>V01.chk</li></ul></li><li>UsrClass.dat</li><li>UsrClass.dat.LOG1</li><li>Caches<ul><li>cversions.1.db</li></ul></li></ul></li><li>Internet Explorer<ul><li>MSIMGSIZ.DAT</li><li>Tiles<ul><li>pin-2845162440<ul><li>msapplication.xml</li></ul></li></ul></li><li>Recovery<ul><li>High<ul><li>Last Active<ul><li>RecoveryStore.{AC08E291-7B19-11E6-917C-0800273C6B02}.dat</li></ul></li></ul></li></ul></li></ul></li><li>Feeds<ul><li>FeedsStore.feedsdb-ms</li><li>{5588ACFD-6436-411B-A5CE-666AE6A92D3D}~<ul><li>WebSlices~<ul><li>Suggested Sites~.feed-ms</li></ul></li></ul></li></ul></li><li>Media Player<ul><li>CurrentDatabase_372.wmdb</li></ul></li></ul></li><li>IconCache.db</li></ul></li></ul></li></ul></li><li>Public<ul><li>Libraries<ul><li>RecordedTV.library-ms</li></ul></li></ul></li></ul></li><li>ProgramData<ul><li>Microsoft<ul><li>Windows Defender<ul><li>Support<ul><li>MPLog-07132009-215552.log</li></ul></li><li>Scans<ul><li>History<ul><li>Service<ul><li>Unknown.Log</li></ul></li></ul></li></ul></li></ul></li><li>Search<ul><li>Data<ul><li>Applications<ul><li>Windows<ul><li>MSS.log</li><li>Windows.edb</li><li>GatherLogs<ul><li>SystemIndex<ul><li>SystemIndex.2.gthr</li><li>SystemIndex.2.Crwl</li><li>SystemIndex.1.Crwl</li><li>SystemIndex.1.gthr</li></ul></li></ul></li><li>MSS.chk</li><li>Projects<ul><li>SystemIndex<ul><li>PropMap<ul><li>CiPT0000.000</li></ul></li><li>SecStore<ul><li>CiST0000.002</li><li>CiST0000.001</li><li>CiST0000.000</li></ul></li><li>Indexer<ul><li>CiFiles<ul><li>CiAD0002.000</li><li>CiAD0002.001</li><li>00010001.ci</li><li>00010008.wid</li><li>00010004.wid</li><li>INDEX.002</li><li>INDEX.001</li><li>INDEX.000</li><li>00010001.dir</li><li>00010006.wid</li><li>CiAB0002.001</li><li>CiAB0002.000</li><li>CiAB0002.002</li><li>00010003.wid</li><li>CiAD0002.002</li><li>00010005.wid</li><li>00010007.ci</li><li>00010009.wid</li><li>00010005.ci</li><li>00010001.wid</li><li>00010005.dir</li><li>00010009.ci</li><li>00010007.wid</li><li>00010009.dir</li><li>00010002.wid</li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li><li>RAC<ul><li>PublishedData<ul><li>RacWmiDatabase.sdf</li></ul></li><li>StateData<ul><li>RacWmiEventData.dat</li><li>RacWmiDataBookmarks.dat</li><li>RacDatabase.sdf</li></ul></li></ul></li><li>Windows<ul><li>DRM<ul><li>drmstore.hds</li></ul></li></ul></li><li>Diagnosis<ul><li>ETLLogs<ul><li>ShutdownLogger<ul><li>AutoLogger-Diagtrack-Listener.etl</li></ul></li></ul></li><li>events01.rbs</li></ul></li><li>IlsCache<ul><li>ilrcache.xml</li><li>imcrcache.xml</li></ul></li><li>Network<ul><li>Downloader<ul><li>qmgr1.dat</li><li>qmgr0.dat</li></ul></li></ul></li></ul></li></ul></li></ul>"><ul class=".actual"><li>Windows<ul><li>setupact.log</li><li>Tasks<ul><li>SCHEDLGU.TXT</li></ul> .... etc.
My Javascript code:
<script>
$(function () {
$('button').on('click', function() {
$('.jstree').jstree();
});
});
</script>
My problem: When the dom of this UL/LI-list is being built and generated by Angular2, the jstree is not getting applied. Instead I receive a normal list.
I tried several ways, having the jstree also loaded on the document ready function, without success:
<script>
$(function () {
$(".jstree").jstree();
}
</script>
Appreciate any help or hint.
Thanks
If you really invoke the code like you shown, Angular app is not in the DOM yet when document ready is called. If you need to use a jQuery plugin inside Angular 2, you should invoke it in a component's ngOnInit. Refer here for sample angular2 component.

Hiding elements until load has been completed (ng-cloak isn't what I needed)

I'm writing an AngularJS application, but I'm quite new to it, so in the code below, please point out any issues that you have.
I do have my AngularJS application defines like that:
var OfficeUIModule = angular.module('OfficeUI', ['ngSanitize']);
Then, I do have a couple of services that loads data from various JSon files.
But i won't post the code here, because I do believe that irrelevant.
Then I do have my controller which basically looks like this:
OfficeUIModule.controller('OfficeUIController', function($scope) { });
Now, I want the controller to execute some logic on startup and show a DIV element on it.
Here's the case what I want to do:
Show a Loading DIV element during initial setup.
Show a Displaying DIV element when the initialization has been done.
Let's say that in my controller I do have method to initialize the application:
OfficeUIModule.controller('OfficeUIController', function($scope) {
function Init() {
// I'll load all the data from the services here.
}
});
In order to call this method on startup, I just define it in my controller like so:
OfficeUIModule.controller('OfficeUIController', function($scope) {
Init();
function Init() {
// I'll load all the data from the services here.
}
});
And the HTML which I would like to use is the following:
<body>
<div id="loading">LOADING</div>
<div id="displaying">DISPLAYING</div>
</body>
When the page is initially loaded, I would like to show the element 'Loading'.
When the page has been loaded, I would like to show the element 'Displaying'.
In order to make this testable, I've changed my controller method Init to include a timeout of 5 seconds, just like below:
OfficeUIModule.controller('OfficeUIController', function($scope) {
Init();
function Init() {
setTimeout(function() {
alert('Page has been loaded. When you click OK the displaying DIV should be showed.');
}, 5000);
}
});
So, in this particular case, I would like to make sure that the page is being loaded, displaying the LOADING div and after 5 seconds, display the DISPLAYING div.
I would also like not to see any flickering, and therefore ng-cloak can be used I've read, but I can't manage to configure it correctly.
Here's what I've tried already:
LOADING
DISPLAYING
However, that setup doesn't work quite well.
I've included a Plunker so that you can test the solution you provide.
It happens because you are using setTimeout with anonymous function and angularjs isn't aware of model change
http://plnkr.co/edit/FJ2lnrmtG7P3HXZuxRkH?p=preview
if you use angularjs $timeout it works
$timeout(function() {
$scope.initialized = true;
}, 5000);
you could also use $scope.$digest() or $scope.$apply to make it work
You can use the angular version of window load event.
angular.element($window).bind('load', function(e) {
// code to execute
});

Combination of $(document).ready and $scope.$on('$viewContentLoaded', function() {...})

I'm using JQuery UI components in a view of AngularJS/JQuery application.
I need something like this (does not work) in my JavaScript code:
$(document).ready(function () {
var elem = $('div[ng-view]')[0];
var $scope = angular.element(elem).scope();
$scope.$on('$viewContentLoaded', function() {
// multiple JQuery statements
// to support JQuery-UI componenets
});
});
This code is included as <script> into index.html that has <div class="container" ng-view> element.
My thinking was that we need a two-step process:
First JQuery reacts on document-ready HTML event and attaches a listener to Angular's $viewContenLoaded using $scope retrieved using [ng-view] element.
Then each time a view is loaded my JQuery code will be executed and JQuery UI components get activated and wired.
Apparently my logic is flawed somewhere. Please point me in the right direction.
ADDITIONAL INFO (posted 03/31/14):
The rest of my code (controllers, service, routing) is written in TypeScript.
That element needs to be compiled in order to bind angulars scope to that element. You could try something like:
var scope = angular.injector(['ng']).get('$rootScope').$new();
var compile = angular.injector(['ng']).get('$compile');
compile(elem)(scope);
scope.$on('$viewContentLoaded', function(){
// Your code
});
Though I would suggest putting your code in a directive. The code I shown above is nothing more than a hack and dangerous since now you have global access to your services.

Ember app kit Application view didInsertElement fired only once

Hi I use Ember app kit and I need to fire a didInsertElement every time I changed route(child view - view in outlet). I need something like global app DOM ready event.
I found mavilein's solution but it doesnt work.
Here is my app/views/application.js:
export default Ember.View.extend({
didInsertElement : function(){
this._super();
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
},
afterRenderEvent : function(){
// implement this hook in your own subclasses and run your jQuery logic there
console.log("FIREEEEE");
}
});
When I run the app it fires the didInsertElement, but when I change route(click on link) it doesnt trigger the application view didInsertElement event.
I know that application view doesnt change, but I need something what fires every time I change child view. Or am I ruining the architecture and do it other way?
Thanks for any help.
Hey #petkopalko from what you said in the comments you want to use Holder.js for placeholder images and like you said you need to execute the Holder.run() function because of how holder.js works. What you can do is add Holder.run() to each view that needs it in the didInsertElement hook but that is not what you want to do and that could get tiresome.
Now from your code above, with Ember App Kit (EAK) and the resolver i think what you are actually doing by saying:
export default Ember.View.extend({...
from within app/views/application.js is actually exporting a View associated with the ApplicationView which is why is will only execute once because the Application View gets insert on page load.
I was doing a little hacking and what seems to work is that you have to reopen Embers view class (object) and add the holder.run in the didInsertElement hook. What seems to work best from me from within EAK with reopening Ember base classes is do it in the app.js file.
That would look like this in app.js file:
Ember.View.reopen({
didInsertElement: function(){
Ember.run.next(function(){
Holder.run();
}
}
});
And it seems to work with just ember.run
Ember.View.reopen({
didInsertElement: function(){
Ember.run(function(){
Holder.run();
}
}
});
And if you want you can keep all you code from before just place it in app.js
Ember.View.reopen({
didInsertElement : function(){
this._super();
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
},
afterRenderEvent : function(){
// implement this hook in your own subclasses and run your jQuery logic there
console.log("FIREEEEE");
//You can place the holder.run() function here and not in views
Holder.run();
}
});
If you dont place Holder.run() in your afterRenderEvent function in the reopen View. You will have to place it in the views afterRenderEvent function that you seems to want.
SomeView = Ember.View.extend({
afterRenderEvent: function() {
this._super();
Holder.run();
}
});
Not sure of side effects with these approaches but you can explore them after implementing. So you have a few options here: Happy coding.
Attached here is a jsbin that seems to illustrate the behavior that i think you are looking for:
http://emberjs.jsbin.com/medamata/6/edit

Backbone :: Using jQuery Plugins on Views

I'm having trouble figuring out a clean way to do this. Let's take for an example a code snippet from the example todo app that comes with backbone:
addOne: function(todo) {
var view = new TodoView({model: todo});
$("#todo-list").append(view.render().el);
},
So the ToDo view is being rendered and then it's being appended to #todo-list. But let's suppose we want to add a jQuery plugin to ToDo view. Where should we place the $(".todo").plugin() snippet? If we place it inside the ToDo view render function the HTML element is not set on the page, so the plugin won't 'latch' to any DOM element. If we place this inside the addOne function it will look ugly.
So, what's the best way?
The answer largely depends on the plugin you're talking about.
For example, most of the jQueryUI controls and the KendoUI controls allow you to call the plugin method from the render of the view, directly, before the HTML is attached to the DOM. You simply call it on the view's el.
For example, if I wanted to use KendoUI's menu on a view that generated:
Backbone.View.extend({
tagName: "ul",
render: function(){
var html = "<li>foo</li><li>bar</li>";
this.$el.html(html);
this.$el.kendoMenu();
}
});
There are some plugins that require the HTML to be a part of the DOM already, for whatever reason. In this case, I typically provide an onShow function in my views, and have the code that is displaying the view check for this and call it if it exists.
For example, there's a "Layout" plugin that I've used a few times. This plugin requires the HTML to be part of the DOM before it can work:
MyView = Backbone.View.extend({
render: function(){
var html = "generate some html here...";
this.$el.html(html);
},
onShow: function(){
this.$el.layout();
}
});
// .... some other place where the view is used
var view = new MyView();
view.render();
$("#someElement").html(view.el);
if (view.onShow) {
view.onShow();
}
FWIW: I've written the code for onShow and other common methods and events dozens of times, and have consolidated it all into a Backbone add-on called Backbone.Marionette, so that I don't have to write it anymore.
http://github.com/derickbailey/backbone.marionette
There's a lot more than just this available in this add-on, of course.
You can use the backbone $ method like so this.$('todo') to use context scoped jquery querying which will allow you to search in the current view DOM fragment which wasn't added to the document DOM tree yet.
From my experience adding jquery plugin binding in either render method or some kind of helper function if there was more custom bindings which would be then called from render method after the template was created.

Categories