fis3-demo
fis3-demo copied to clipboard
fis3-angular-demo
源码 angular.module('example', []).config(function($stateProvider, $urlRouterProvider) { $stateProvider.state('example', { url: '/example', template: __inline('./example.html') }).state('example.dropdown', { url: '/dropdown', templateUrl: __inline('./dropdown.html') }); }); 编译后: define('example', function(require, exports, module) { 'use strict'; angular.module('example', []).config(function($stateProvider, $urlRouterProvider) { $stateProvider.state('example', { url: '/example', template: "<div class="col-md-2">\r\n<a ui-sref="example.dropdown" class="btn btn-success">dropdown\r\n" }).state('example.dropdown', { url: '/dropdown', template: "dropdown.html" }); }); });
问题 dropdown.html内容为什么没加载进来?
我们是直接把 template 编译成 js,而不再发起另外一个请求。
__inline是内容嵌入语法,直接把html嵌入到js里面,所以应该加在template而不是templateUrl后面,grunt也有类似的插件把html嵌入到js里面,而fis直接用嵌入语法就行了。这是推荐的做法,否则html内容改变可能被缓存住导致页面未更新