2017-12-03 8 views
0

각도 변수를 Notify.js 함수에 전달할 수있는 방법이 있습니까? 함수 내에서 $ .notify()를 사용하여 Angular 범위에서 내 함수를 만들려고했으나 실행되지 않습니다. 일반 JS 함수로 응용 프로그램의 범위를 벗어난 함수를 이동하면 잘 실행되지만 Angular에 저장된 데이터를 사용할 수 없습니다.

나는이 :

function showAchievement() { 
    $.notify({ 
    title: '{{angularData}}', 
    message: '{{moreData}}.' 
    }, { 
    type: 'achievement', 
    placement: { 
     align: "left" 
    }, 
    animate:{ 
     enter:'animated fadeInLeft', 
     exit:'animated fadeOutRight' 
    }, 
    delay: 5000 
    }); 
} 

내 CSS :

.alert-achievement { 
    background: url("../img/purple-bg.png") no-repeat; 
    border: 4px solid purple; 
    color: dodgerblue; 
    padding: 10px; 
    width: 25%; 
} 

.alert-achievement > [data-notify="title"] { 
    color: purple; 
    text-align: center; 
    display: block; 
    font-weight: bold; 
    margin-bottom: 5px; 
} 

.alert-achievement > [data-notify="message"] { 
    font-size: 80%; 
} 

그것은 각도의 잘 외부에서 작동합니다. Angular 내부에서도 트리거됩니다. Angular $ scope.title의 내용에 따라 제목과 메시지를 전달하면됩니다. 함수에

답변

0

넣어 파라미터 :

function showAchievement (title, message) { 
    $.notify({ 
    title: title, 
    message: message + '.' 
    }, { 
    type: 'achievement', 
    placement: { 
     align: "left" 
    }, 
    animate:{ 
     enter:'animated fadeInLeft', 
     exit:'animated fadeOutRight' 
    }, 
    delay: 5000 
    }); 
} 

그럼 인수로 범위 변수와 함수 호출은 :

자세한 내용
showAchievement($scope.angularData, $scope.moreData); 

, MDN JavaScript Reference - functions 참조.

+0

감사! 실제로 시도했지만 angleData 앞에 $ scope를 추가하는 것을 잊어 버렸습니다. IDE가 인식했지만 작동하지 않았습니다. 죄송합니다. – Thranor