小编Phi*_*ice的帖子

在angularjs中未定义Toastr

我正在做教程,这部分是关于实现登录,这应该给出关于登录成功的气球

angular.module("app").value("mvToastr", toastr);

angular.module("app").factory("mvNotifier", function(mvToastr) {
   return {
      notify: function(msg) {
          mvToastr.success(msg);
          console.log(msg);
       }
    }
});
Run Code Online (Sandbox Code Playgroud)

我得到了这个,我不明白它.似乎加载了所有.js文件.请告诉我问题出在哪里,谢谢.

TypeError: Cannot call method 'extend' of undefined
   at getOptions (http://localhost:3030/vendor/toastr/toastr.js:282:14)
   at Object.success (http://localhost:3030/vendor/toastr/toastr.js:68:17)
   at Object.notify (http://localhost:3030/app/common/mvNotifier.js:6:22)
   at http://localhost:3030/app/account/mvNavBarLoginCtrl.js:8:28
   at wrappedCallback (http://localhost:3030/vendor/angular/angular.js:11033:81)
   at wrappedCallback (http://localhost:3030/vendor/angular/angular.js:11033:81)
   at http://localhost:3030/vendor/angular/angular.js:11119:26
   at Scope.$eval (http://localhost:3030/vendor/angular/angular.js:12045:28)
   at Scope.$digest (http://localhost:3030/vendor/angular/angular.js:11871:31)
   at Scope.$apply (http://localhost:3030/vendor/angular/angular.js:12151:24)

   angular.js:9503
Run Code Online (Sandbox Code Playgroud)

jquery undefined angularjs toastr

13
推荐指数
1
解决办法
8976
查看次数

AngularJS:通过插值观察被转换的内容变化?

我把一个最能说明问题的傻瓜放在一起.

我正在尝试编写一个简单的指令,它将从指令更新transcluded html.

例如,我想:

<make-bold>Foo *bar* {{something}}</make-bold> 
Run Code Online (Sandbox Code Playgroud)

生成

<span>Foo <b>bar</b> somevalue<span>  
Run Code Online (Sandbox Code Playgroud)

关于plunker的例子工作得很好,但我无法弄清楚如何获得被转换内容的通知(观察)变化.在示例中,尝试选择不同的项目(通过单击它们),您将注意到"已处理"不会更新.

我很确定问题是传递给链接函数的元素没有更新,但它是内容更新,因此无法观看.

指示

app.directive('makeBold', function($interpolate, $timeout, $compile)
{

  var regex = new RegExp("\\*(.+?)\\*", 'g');
  var replace = "<b>$1</b>";

  return {
    restrict: 'E',
    transclude: true,
    replace: true,
    template: '<span ng-transclude></span>',
    link: function (scope, element, attrs)
    {
      scope.$watch(
        function() { 
          // *** What do I need to watch here? ***
          return element;
        }, 
        function(n, o) {
          var text = $interpolate(element.text())(scope); 
          var newContent = text.replace(regex, replace);
          $timeout(function() { element.html(newContent); }); …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive

4
推荐指数
1
解决办法
3397
查看次数