【问题标题】:ui-Router templateUrl not able to find $templateCache template in app-release.jsui-Router templateUrl 在 app-release.js 中找不到 $templateCache 模板
【发布时间】:2018-02-18 12:24:33
【问题描述】:

我使用Gulp-angular-templatecache 将我的html 模板缓存到templates-cache.js 中,然后我使用Gulp-browsify 编译我的app.js 文件以生成app-release.js 文件,其中包含 app.js 和 templates-cache.js 文件中的所有代码。

app.js 包含所有依赖项,包括生成的 templates-cache.js 文件,但ui.route 无法调用templateUrl 上的html 文件我遵循https://docs.angularjs.org/api/ng/service/$templateCache 的角度指南但我仍然找不到问题。

app.js

import angular from "angular";
import uiRouter from "@uirouter/angularjs";
let template = require("../../templates-cache.js");

let app = angular.module("app", [uiRouter]);

app.config(function ($stateProvider) {

    let Default = {
        name: "default",
        url: "/",
        templateUrl: "home.html"
    };

    let Home = {
        name: "home",
        url: "",
        templateUrl: 'home.html'
    };

    $stateProvider.state(Home);

});

app-release.js

app.config(function ($stateProvider) {

    var Default = {
        name: "default",
        url: "/",
        templateUrl: "home.html"
    };

    var Home = {
        name: "home",
        url: "",
        templateUrl: 'home.html'
    };


    $stateProvider.state(Home);
});


},{"../../templates-cache.js":77,"@uirouter/angularjs":1,"angular":75}],77:[function(require,module,exports){
'use strict';

angular.module('template', []).run(['$templateCache', function ($templateCache) {

  $templateCache.put('home.html', '\n<div class="largeText">My Angular App</div>\n\n');

}]);

Chrome 中的错误 Error in Chrome

感谢您的帮助:)

【问题讨论】:

    标签: angularjs gulp angular-templatecache


    【解决方案1】:

    问题就在这里。我没有注入由 gulp-angular-templatecache 生成的template

    修复

    let app = angular.module("app", [uiRouter, "template"]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-29
      • 2015-12-08
      • 2016-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多