1
jquery 호출을 Angular js로 변환하는 방법을 배우고 있습니다. 나는 이전에 내가 추가 할 필요가이를 위해 ziplookupAngularJS 컨트롤러에서 자바 스크립트 함수 호출
사용하여 볼 우편을위한 웹 페이지 구축 :
<script src="http://ziplookup.googlecode.com/git/public/ziplookup/zipLookup.min.js" type="text/javascript">
</script>
및
$(document).ready(function() { // When the document loads,
$.zipLookupSettings.libDirPath = 'ziplookup/' // (Optionally) set the library folder path manually
$('[name=zipcode]').blur(function(){ // Set on blur
$.zipLookup( // Do a Zip code Lookup
$(this).val(), // Zip code Field Value
function(cityName, stateName, stateShortName){ // If Successful,
$('input[name=city]').val(cityName); // Set City name
$('input[name=state_short]').val(stateName); // Set State abbreviation
$('input[name=state]').val(stateShortName); // Set State name
$('.message').html("Found Zipcode"); // Add a message
},
function(errMsg){ // If Zip couldn't be found,
$('.message').html("Error: " + errMsg); // Add an error message
});
});
});
이 지금은이 각도 JS에 포트하고자합니다. blur 이벤트에서 zipLookup 함수를 호출하는 대신 버튼 누르기에서 호출하는 중입니다. 같은 매개 변수를 설정하지만이 제공 :
ReferenceError가 : zipLookupSettings 것은 또는
ReferenceError가 정의되지 않습니다 zipLookup 가이드하시기 바랍니다 $scope.zipeval = function(){
//zipLookupSettings.libDirPath = 'ziplookup/';
zipLookup( // Do a Zip code Lookup
11722, // Zip code Field Value
function(cityName, stateName, stateShortName){ // If Successful,
$log.log(cityName + stateName + stateShortName);
//$('input[name=city]').val(cityName); // Set City name
//$('input[name=state_short]').val(stateName); // Set State abbreviation
//$('input[name=state]').val(stateShortName); // Set State name
//$('.message').html("Found Zipcode"); // Add a message
},
function(errMsg){ // If Zip couldn't be found,
$log.log("error"); // Add an error message
});
};
를 정의되어 있지 않습니다. 지침을 작성해야합니까?
jquery 버전 작업을 위해 바이올린을 추가 할 수 있습니까? – Quad
당신은'$ .zipLookup' 대신에 zipLookup을 사용하고 있습니다. 어쨌든 지시문이나 서비스에서 jquery 플러그인을 래핑하는 것이 좋습니다. – link