angular细节整理
记录angularjs中比较容易忽视的问题
1、关于动态生成ui-sref的问题
ui-route中ui-sref中的路径无法动态生成的,如果要实现动态生成ui-sref路径,可以使用$state.go做跳转:
if($location.path().substring(8,14) == 'zrssjg'){
$state.go('sousuo.zrssjg', {topic:$scope.keyWord}, { reload: true });
}else if($location.path().substring(8,14) == 'dtssjg'){
$state.go('sousuo.dtssjg', {topic:$scope.keyWord}, { reload: true });
}else if($location.path().substring(8,14) == 'nmssjg'){
$state.go('sousuo.nmssjg', {topic:$scope.keyWord}, { reload: true });
}else if($location.path().substring(8,14) == 'htssjg'){
$state.go('sousuo.htssjg', {topic:$scope.keyWord}, { reload: true });
}else if($location.path().substring(8,14) == 'zwssjg'){
$state.go('sousuo.zwssjg', {topic:$scope.keyWord}, { reload: true });
}
//ifelse==>
$scope.doSerchClick = function(item) {
$scope.sType = {'0':'sousuo.zrssjg', // 找人搜索结果
'1':'sousuo.dtssjg', // 实名动态
'2':'sousuo.nmssjg', // 匿名动态
'3':'sousuo.htssjg', // 话题
'4':'sousuo.zwssjg'}[item] || 'zrssjg'; // 职位 || 找人
$scope.keyWord = '';
}
2、使用$templateCache服务动态绑定html页面中ng-bind内容:
$scope.toTrends = function(type) {
if (type == 1) {
$templateCache.put('templateId.html', '{{reply.replier.realName}}:');
$templateCache.put('template.html','{{data.dynamicRef.dynamicShare.publisher.realName}}:');
} else {
$templateCache.put('templateId.html','{{reply.replier.account.nickName}}:');
$templateCache.put('template.html','{{data.dynamicRef.dynamicShare.publisher.account.nickName}}:');
}
$scope.typeStatus = type;
pushContent($scope.typeStatus);
};
//html:
<span class="dyn-content-ref" ng-include=" 'template.html' "></span>
//这边的template.html能根据vontroller中的状态动态生成,同时也能实现双向绑定的效果
3、element匹配元素
angular.element(document.querySelector('.a'))
4.$sce服务
我们用ng-bind-html这样的指令来绑定一段动态生成的html,结果不是我们想要的,
例如:$scope.currentWork.description = “hello,<br><b>今天我们去哪里?</b>”
我们用ng-bind-html这样的指令来绑定,结果却不是我们想要的。是这样的
hello,
今天我们去哪里?
怎么办呢?、
结果是将样式与html标记过滤掉了,我们可以使用$sce服务来解决这个问题
:$scope.currentWork = work;
$scope.currentWork.description = $sce.trustAsHtml($rootScope.currentWork.description);
把它封装成一个过滤器就可以在模板上随时调用了
app.filter('to_trusted', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
};
}]);
html code:<p ng-bind-html="currentWork.description | to_trusted"></p>
angular细节整理的更多相关文章
- ffmpeg细节整理记录
ffmpeg细节整理记录 1.-vcodec.-code:v.-c:v ffmpeg的官方文档 -vcodec 是 -code:v 别名. -vcodec codec (output) Set the ...
- CSS面试细节整理(一)
最近面试时候发现自己最熟悉的css确实开发中好多细节没注意到,为了防止在栽跟头,打算从头到底捋一遍咯 语法部分: 1.css几种选择器的写法 (1)h1 em {color:red;} (后代选择器) ...
- Java细节整理——数组与内存控制
重点:使用Java数组之前,必须对数组对象进行初始化. 当数组的所有元素都被分配了合适的内存空间,并指定了初始值时,数组的初始化完成.程序以后将不能重新改变数组对象在内存中的位置和大小. 知识点整理: ...
- Unity投影器细节整理
抽了个空整理下投影器 一般投影器需要两张贴图,一张Cookie,一张FallOff. Unity提供Light和Multiple两种自带shader,和粒子类似. Cookie需要非alpha贴图,F ...
- iOS开发笔记18:一些编译、开发调试、打包的细节整理
1.以链库的方式引用第三方库 一些特殊场景可能会要求使用链库的方式使用第三方库,大体设置如下: ①Other Linker Flags里进行设置,格式为-l+库名称 ②Libray Search Pa ...
- iOS-技术细节整理
遇到未使用类,可以看看xcode->help->developer documentation 下面做一下简单的技术细节整理 Auto Layout使用Auto Layout来灵活改变UI ...
- spark shuffle 相关细节整理
1.Shuffle Write 和Shuffle Read具体发生在哪里 2.哪里用到了Partitioner 3.何为mapSideCombine 4.何时进行排序 之前已经看过spark shuf ...
- C#中容易被忽视的细节整理
(有空更新系列) 1.params可变长度参数,默认值是长度为0的数组,而不是空 2.事件和委托默认值都是null 3.bool返回值的事件调用之后,其内部的合并方式是取最后一个合并对象的返回值
- Unity3D细节整理:AssetBundle对应的各种格式文件的类型
我们打包AssetBundle后,Unity3D会根据文件的后缀名将文件转换为特定的类型对象存储起来,我们后期获取时需要根据这些类型取出打包的数据,这里记录下不同后缀文件打包后的类型. 文本格式 支持 ...
随机推荐
- 兼容PHP和Java的des加密解密代码分享
这篇文章主要介绍了兼容PHP和Java的des加密解密代码分享,适合如服务器是JAVA语言编写,客户端是PHP编写,并需要des加密解密的情况,需要的朋友可以参考下 作为一个iOS工程师来解决安卓的问 ...
- bzoj2687: 交与并
Description 对于一个区间集合{A1,A2……AK}(K>1,Ai<>Aj{i<>j}),我们定义其权值 W=|A1∪A2∪……∪A ...
- 欧拉计划(1~3)ps:以后看题一定要认真
那天的题挺简单的 下面来看下 No1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get ...
- GNU project C
gcc - GNU project C and C++ compiler gcc [option] file... preprocessing compila ...
- Unity3D 3D横版跑酷
Unity3d 3D横版跑酷系列(Character Controller组件) @广州小龙 目前在做一个3D跑酷的横版游戏,目前说一下 Character Controller组件! 1.Slop ...
- Inna and Sequence
Codeforces Round #220 (Div. 2) D:http://codeforces.com/contest/374/problem/D 题意:给你m个数,这m个数是递增的.然后给你n ...
- Android中attr自定义属性详解
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:wen=http ...
- Oracle 多版本控制
SESSION 1: SQL> create table t 2 as 3 select * from all_users; Table created. SQL> variable x ...
- Building a Space Station(kruskal,说好的数论呢)
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3820 Accepted: 1950 Description You a ...
- SQL时间格式化
1 取值后格式化 {:d}小型:如2005 {:D}大型:如2005年5月6日 {:f}完整型 2 当前时间获取 DateTime.Now.ToShortDateString 3 取值中格式化SQL ...