错误:使用grunt运行时未定义AngularJs变量。 (zetzer)

时间:2015-01-05 11:19:16

标签: javascript angularjs gruntjs

使用终端运行GRUNT时出现错误:

错误:

跑步" zetzer:main" (zetzer)任务 警告:未定义模板使用--force继续。

因警告而中止。

代码:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example - example-example83-production</title>
  <style>
 .slide-animate-container {
  position:relative;
  background:white;
  border:1px solid black;
  height:40px;
  overflow:hidden;
}

.slide-animate {
  padding:10px;
}

.slide-animate.ng-enter, .slide-animate.ng-leave {
  -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
  transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;

  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
  display:block;
  padding:10px;
}

.slide-animate.ng-enter {
  top:-50px;
}
.slide-animate.ng-enter.ng-enter-active {
  top:0;
}

.slide-animate.ng-leave {
  top:0;
}
.slide-animate.ng-leave.ng-leave-active {
  top:50px;
}

  </style>


  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js">     
  </script>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-animate.js">   
  </script>
  <script>

 (function(angular) {
 alert("hello");
angular.module('includeExample', ['ngAnimate'])
  .controller('ExampleController', ['$scope', function($scope) {
    $scope.templates =
      [ { name: 'template1.html', url: 'template1.html'},
        { name: 'template2.html', url: 'template2.html'} ];
    $scope.template = $scope.templates[0];
    $scope.name = "World";
  }]);
})(window.angular);

  </script>

</head>
<body ng-app="includeExample">
  <div ng-controller="ExampleController">
 <select ng-model="template" ng-options="t.name for t in templates">
     <option value="">(blank)</option>
 </select>
 url of the template: <code>{{template.url}}</code>
 <p>Hello, {{name}}! </p>
 <div ng-include="'template1.html'"></div>
 <div class="slide-animate-container">
    <div class="slide-animate" ng-include src="'template1.html'"></div>
 </div>
  </div>
   <div class="slide-animate-container">
    <div class="slide-animate" ng-include src="'template1.html'"></div>
 </div>
</body>
</html>

其他信息:

此代码在直接运行时效果很好。 (来自src文件夹,但我需要使用它运行GRUNT。)

非常感谢任何帮助。

谢谢!

1 个答案:

答案 0 :(得分:0)

我有同样的错误,对我来说这是因为zetzer与angularJS冲突。

在我的grunt文件中,我更改了dot.templateSettings以引用“evaluate”的三个大括号{{{}}},而不是Angular使用的两个{{}}。

doT.js documentation(由zetzer使用)查看API标题

您需要在我的代码中查看的行是:

...评价

zetzer: {
  dev: {
    options: {
      partials: "dev/partials",
      templates: "dev/templates",
      dot_template_settings: {
        evaluate:    /\{\{\{([\s\S]+?)\}\}\}/g,
      }
    },
    files: [
      {
        expand: true,
        cwd: "dev/",
        src: ["**/*.html", "!partials/**/*.html"],
        dest: "dist/",
        ext: ".html",

      }
    ]
  },
},