记录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细节整理的更多相关文章

  1. ffmpeg细节整理记录

    ffmpeg细节整理记录 1.-vcodec.-code:v.-c:v ffmpeg的官方文档 -vcodec 是 -code:v 别名. -vcodec codec (output) Set the ...

  2. CSS面试细节整理(一)

    最近面试时候发现自己最熟悉的css确实开发中好多细节没注意到,为了防止在栽跟头,打算从头到底捋一遍咯 语法部分: 1.css几种选择器的写法 (1)h1 em {color:red;} (后代选择器) ...

  3. Java细节整理——数组与内存控制

    重点:使用Java数组之前,必须对数组对象进行初始化. 当数组的所有元素都被分配了合适的内存空间,并指定了初始值时,数组的初始化完成.程序以后将不能重新改变数组对象在内存中的位置和大小. 知识点整理: ...

  4. Unity投影器细节整理

    抽了个空整理下投影器 一般投影器需要两张贴图,一张Cookie,一张FallOff. Unity提供Light和Multiple两种自带shader,和粒子类似. Cookie需要非alpha贴图,F ...

  5. iOS开发笔记18:一些编译、开发调试、打包的细节整理

    1.以链库的方式引用第三方库 一些特殊场景可能会要求使用链库的方式使用第三方库,大体设置如下: ①Other Linker Flags里进行设置,格式为-l+库名称 ②Libray Search Pa ...

  6. iOS-技术细节整理

    遇到未使用类,可以看看xcode->help->developer documentation 下面做一下简单的技术细节整理 Auto Layout使用Auto Layout来灵活改变UI ...

  7. spark shuffle 相关细节整理

    1.Shuffle Write 和Shuffle Read具体发生在哪里 2.哪里用到了Partitioner 3.何为mapSideCombine 4.何时进行排序 之前已经看过spark shuf ...

  8. C#中容易被忽视的细节整理

    (有空更新系列) 1.params可变长度参数,默认值是长度为0的数组,而不是空 2.事件和委托默认值都是null 3.bool返回值的事件调用之后,其内部的合并方式是取最后一个合并对象的返回值

  9. Unity3D细节整理:AssetBundle对应的各种格式文件的类型

    我们打包AssetBundle后,Unity3D会根据文件的后缀名将文件转换为特定的类型对象存储起来,我们后期获取时需要根据这些类型取出打包的数据,这里记录下不同后缀文件打包后的类型. 文本格式 支持 ...

随机推荐

  1. vs2013update4 vs-mda-remote cordova真机测试ios 解决里面一个坑

    sudo npm install -g vs-mda-remote --user=你的用户名 此步骤为安装vs-mda-remote,如果安装成功 执行vs-mda-remote –secure fa ...

  2. WebApp 中用 hashchange 做路由解析

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 应用tomcat(Linux中安装)

    CentOS 7 中安装 tomcat. 下载 Tomcat Wget 下载 Tomcat Tomcat 官网中找到指定版本 Tomcat rpm 的 url 使用 wget url 下载 rpm , ...

  4. Cow Exhibition

    poj2184:http://poj.org/problem?id=2184 题意:给你n头牛,每头牛有一个S值和一个F值,现在的问题是,要你选出其中的一些牛求出S+T的最大值.但是要保证总的s> ...

  5. 辉哥用的这种方法实现ZABBIX的MYSQL批量监控

    不错的.集中和分布式,总是一对要解决的问题.应该可以再想更好的策略~~ 一.方案需求及思路 因跑MySQL服务的服务器比较多,并且每台服务器可能会运行多个不同端口的数据库,如果单独手动一台一台去修改a ...

  6. 关于如何在BCB中使用CodeGuard

    作者:深圳虫 来自:深圳虫网本文来自http://www.szbug.com/disparticle.aspID=4 一. 为什么写这篇东西自己在使用BCB5写一些程序时需要检查很多东西,例如内存泄漏 ...

  7. 两款商业拓扑发现软件siteview和ElementSentry的比较

    今天在公司试用了一下两款商业拓扑发现软件游龙科技的siteview和速方软件ElementSentry. 条目/产品 速方软件ElementSentryv5.0 游龙科技Siteview NNM v3 ...

  8. MySQL 没有索引 锁全表

    <h3 class="title" style="box-sizing: inherit; margin: 8px 0px 15px; padding: 0px; ...

  9. 解决Failed to connect session for conifg 故障

    服务器升级openssh之后jenkins构建报错了,报错信息如下: Failed to connet or change directory jenkins.plugins.publish_over ...

  10. HDU 5478 Can you find it(数学问题)

    题目大意: 给你  ak1⋅n+b1+ bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...). 要求所有的n都满足上述的式子. 问这样的a,b 有多少对?   分析这个问题 ...