Qeb Archives: Angular

Trouble-shooting taub rau kev tswj Angular (Los sis, Kev hlub Hyphens tag li rov)

Kuv muaj ib ob peb apps ua ntawd tus tsim $http.get() Yog hais lus thiab kuv xav tau los qhia cov nicely formatted yuam kev lus nrog dab tuag yuam kev txhawb muab zais, tab sis puas siv tau.  Yeej, qhov no:

image

Thiab ntawd los yog tus neeg siv ntawm qhov yuam kev clicks, lawv pom ntau info:

image

Khoom yooj yim.  Vim lub caij nyoog tib neeg yuam kev yuav tshwm sim rau cov thawj tswj kev tshuaj ntsuam thiab raws li qhov tus kawg neeg screen, nws qhia meej hu rau Angular tus tswj kev cai.  KUV  nyob nov koj series ntawm cov khoom (http://weblogs.asp.net/dwahlin/creating-custom-angularjs-directives-part-i-the-fundamentals) los ntawm cov great Dan Wahlin.  Raws li nws lub tswv yim, Kuv sai heev tsim ib <nyob zoo-ntiaj teb> tswj thiab nyuam qhuav txav los rau kuv ntxiv txog txoj kev ua yuam kev zaub squeegee. Kuv yuav khiav mus ua teeb meem rau ntau tus tswj no me ntsis.  Kaj siab lug, tsawm tsawv thiab tau muab sij hawm, Kuv twb hais rau WebStorm (editor rau kuv hnub no siv) tias ntawv JS yog ib tug Angular tej ntaub ntawv thiab nws pab kuv paub tseeb ntawm cov teebmeem.  Qhov no yog txoj cai rau tus tswj nws tus kheej:

angular.Module("CDLApp").tswj("generalCdlErrorHandler", muaj nuj nqi() {

rov qab los {
caiv: "E",
hloov: tseeb,

tau: {
retrieveLastConfigurationError: "&"
},

Template:
'<div hoob "qhia alert phom sij =" tug = "ceeb toom" ng-init = "doShowExpandedErrorDetails = tseeb" ng-yeeb yam = "retrieveLastConfigurationError()">' +
' Yog muaj ib qho kev ua yuam kev I/O los yog lwm yam kev ua yuam kev. Feem ntau zoo li no vim hais tias configuration cov ntaub ntawv cov ntaub ntawv yuav tsis yog ' +
' nyob los yog configuration ntawv muaj cov lus tsis tseeb (xws li referencing lub tsev qiv ntawv ntawv ' +
' uas tsis nyob ua ib ke).' +
' <br />' +
' <div ng-yeeb yam = "doShowExpandedErrorDetails">' +
' <ib tug href = "#" ng nias = "doShowExpandedErrorDetails = ! doShowExpandedErrorDetails">' +
'Nyem qhov no mus nkaum lus.' +
' </ib tug>: ' +
' <br />' +
' <txaus>{{retrieveLastConfigurationError() | json}}</txaus>' +
' <br />' +
' </div>' +
' <div ng-yeeb yam = "!doShowExpandedErrorDetails">' +
' <ib tug href = "#" ng nias = "doShowExpandedErrorDetails = ! doShowExpandedErrorDetails">' +
'Nyem qhov no mus nthuav cov lus yuam kev.' +
' </ib tug>' +
' </div>' +
'</div>'
};
});

Yeej, Kuv yuav tsim ib tug tshiab caij hu ua tus "generalCdlErrorHandler".  Nws yuav tsum tau ua kom ib tug hu ua retrieveLastConfigurationError thiab uas yog leej twg nyob rau qhov uas tus tau txais kwv.  Kuv ntshe yuav tau cia li siv tus niam / txiv uas, tab sis, txoj kev uas pom tau tias tub nkees.  Yog leej twg xav tias kuv yuav tsum tau ua li ntawd, Kuv yuav hlub hnov txog qhov ntawd nyob hauv koj cov lus.

Qhov no ua zoo tag nrho, tab sis kuv tsis tau dab tsi.  Tsis muaj cov uas tsis plaws tom nyob rau hauv cov console (Thaum kawg kuv tas txhua tus sx kom raug kuv tsim ib txoj kev).  Kuv tsuas tsis tau muaj tso zis los ntawm cov tswj.  Mus ua ntxiv ib co ntawv ua ntej tus cwj ng tswj thiab kuv zoo li qub * ua * tau tias. Qhov no los kuv xav tias kab tias txoj kev tswj tsis pub implicitly tsim tshiab vars xws li "doShowExpandedErrorDetails" los yog muaj tus "ng-init" nyob rau ntawd. 

Kuv mus rov qab mus ua qhov HTML saib tias kuv muaj ib yam thiab lub sij hawm no WebStorm hlais kuv.  Kuv twb raug tau dua nyob hauv txoj kev ua retrieveLastConfigurationError li no:

<General-cdl-yuam kev-handler retrieveLastConfigurationError="CDLController.retrieveLastConfigurationError()">
</General-cdl-yuam kev-handler>

Tab sis nws yeej yuav tsum tau ua qhov no:

<General-cdl-yuam kev-handler retrieve-xeem-configuration-yuam kev = "CDLController.retrieveLastConfigurationError()">
</General-cdl-yuam kev-handler>

WebStorm yuav tau ntse txaus kom paub tias nws yuav tsum tau muaj hyphenated.  Yog hais tias nws tsis tau yog muab qhov hint, Kuv xav ntshe yuav tseem troubleshooting qhov no Luag nyav.  Fun zaug!

Qhov ua kom yuam kev no puas yog: tsis tsuas yog tus tswj cov caij npe hyphenated, li ntawd, yog yam muab ntxiv rau nws.  Ib zaug kuv ntxiv cov hyphens, txhua yam nws ua haujlwm great.  Dan tus nyeem tshwm sim siv npe luv luv xwb, ces kuv tsis ua qhov kev twb kev txuas.

Qhov no yuav pab lwm tus neeg vam.

</kawg>

undefinedSubscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

HTTP 406 Yuam kev thaum uas siv cov Angular $http.get tiv thaiv SharePoint so kawg ntsiab lus

Hloov tshiab: Marc AD ndersson taw tes qhia tawm no zoo kawg thiab daim info: http://blogs.Office.com/2014/08/13/json-Light-Support-rest-sharepoint-API-Released/. Uas piav txog heev :).

Uas tej zaum yuav tau lub npe phem ntawm ib cov ncej blog puas! Anyhoo.

Kuv mas ua rau kuv prototyping rau thaj O365. Kuv tau kuv tus kheej lom kom kuv tsis muaj yuav txhawj xeeb txog koj rau leej twg. Ua tus ib cag-nco thaum peb hu kwv ncig cov cav tov virtual rau peb laptops nrog NTXHUAB – SQL neeg rau zaub mov, IIS, txiav txim siab seb vs Hyper-V. VMWare? Anyhoo...

Kuv tau tsim ib qho app Angular siv nyob rau hauv qhov chaw uas puas, cov lwm yam, qhov no:

$http.Get(serverUrl)
.zoo(muaj nuj nqi(cov ntaub ntawv, xwm txheej, headers, config) {

Var getLinksResponse = ntaub ntawv;

getLinksResponse.value.forEach(muaj nuj nqi(theResult) {

// li ntawd thiab ces froth

Qhov no yog ua hauj lwm xwb fine ob hom SharePoint nyob rau hauv tej kev kawm. Txawm li cas los, Thaum twg kuv colleague ported nws mus rau ib Cloudshare lom, nws tsis yog ib tug HTTP 406 yuam kev (uas yog thawj zaug kuv puas tau mus txog ntawd ib tug, vim li ntawd... yay, tej zaum). Peb puas muaj me ntsis kev soj ntsuam thiab pom tias header uas muaj "Txais" tus ntawd tawm. SharePoint hauv Internet yog txawm zoo siab nrog:

Txais: daim ntawv thov/json

Tab sis qhov cloudshare lom (Nws yog ib qho SP rau prem, hosted rau ib tug neeg rau zaub mov virtual) xav qhov classic "odata = verbose" ntxiv rau kom zoo:

Txais: daim ntawv thov/json;odata = verbose

Kho uas, peb ntxiv cov header zoj:

Var config = {headers: {
'Lees': ' thov/json;odata = verbose'
}
};

$http.Get(serverUrl,config)
.zoo(muaj nuj nqi(cov ntaub ntawv, xwm txheej, headers, config) {

Var getLinksResponse = ntaub ntawv;

getLinksResponse.value.forEach(muaj nuj nqi(theResult) {

// li ntawd thiab ces froth

Uas tau mus tua ntawm tus 406, tiam sis nws kuj hloov cov hom ntawv uas yuav teb. Yog xav paub ntxiv … verbose. (haha!) Muaj ntau yam hloov ntxiv yuav tsum thiab nov yog qhov tshwm sim zaum kawg:

Var config = {headers: {
'Lees': ' thov/json;odata = verbose'
}
};

$http.Get(serverUrl,config)
.zoo(muaj nuj nqi(cov ntaub ntawv, xwm txheej, headers, config) {

Var getLinksResponse = ntaub ntawv;

getLinksResponse.d.Results.forEach(muaj nuj nqi(theResult) {

// li ntawd thiab ces froth

Qhov no tsuas txia ntshis ua ib tug 30 teeb meem feeb rau peb, kom peb lucked. Hopefully ib tug neeg pom qhov no pab tau.

</kawg>

How-to: Pab kom muaj ntau yam Angular SharePoint Web nyob rau ib sab

No blog posts piav li cas yuav muaj ntau yam Angular.js raws li qhov chaw web site SharePoint (hais los ntawm ib editor cov Web site qhov) nyob rau ib sab. Kuv hu editor cov Web site qhov (CEWP) uas chiv keeb JavaScript ua tau siv lub moj khaum Angular.js ib "Angular Web txoj kev."

Angular txoj kev bootstrap yog super yooj yim thiab li xwb txhua piv txwv uas koj pom hauv lub internets huas muaj tej yam zoo li no:

<html ng-app = 'myApp'>

<blah /><blah /><blah />

</html>

Qhov no lov, Txawm li cas los, Yog koj xav pab kom ntau CEWP ntawv nthuav ntau yam angular web nyob rau ib sab. Angular yuav yeej tsuas bootstrap tiv thaiv cov ng app thawj tswj nws pom – kawg as of angular version 1.3.6. Cov tshuaj yog zoo nkauj yooj yim – manually bootstrap koj chaws xwb. Cov saum no tam sim no nws ho hloov kev tej yam zoo li no:

<lub cev>
<d
IV daim id =”bootstrapHere” ng maub los =”myController ua theController”>
<blah /><blah /><blah />
</div>
</lub cev>

<tsab ntawv src =”//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js”></tsab ntawv>

<tsab ntawv>
angular.bootstrap(angular.element(document.getElementById(“bootstrapHere”)),['myApp']);
</tsab ntawv>

Yeej, tsis txhob siv ng app rau lub caij ua koj bootstrapping, koj npuaj ib tug ID rau tus ntawd lub caij. Ces, siv cov bootstrap() txoj kev angular rau nws tus kheej uas tswj cov bootstrapping txheej txheem lub sij hawm mus dhia. Kuv twb sim no nrog peb yam txawv Angular web nyob rau ib sab thiab nws ua haujlwm ib lub nplhaib.

</kawg>

undefinedSubscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin