使用AngularJS的Notify.js:将$ scope内容传递给通知

时间:2017-12-03 21:22:14

标签: javascript angularjs notify

有没有办法将Angular变量传递给Notify.js函数? 我已尝试在函数内部使用$ .notify()在Angular的范围内创建函数,但它不会运行。如果我将该函数移动到应用程序范围之外作为普通的JS函数,它运行得很好但是我不能在其中使用Angular存储数据。

我有:

distGeo

和我的CSS:

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

它在Angular之外工作得很好。甚至在Angular中触发它。我只需要根据Angular $ scope.title的内容传递标题和消息。

1 个答案:

答案 0 :(得分: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