www.91084.com

GVKun编程网logo

javascript – Thymeleaf值发送angularJS ng-onclick方法(angular发送http请求)

10

本文将分享javascript–Thymeleaf值发送angularJSng-onclick方法的详细内容,并且还将对angular发送http请求进行详尽解释,此外,我们还将为大家带来关于angu

本文将分享javascript – Thymeleaf值发送angularJS ng-onclick方法的详细内容,并且还将对angular发送http请求进行详尽解释,此外,我们还将为大家带来关于angularjs unsafe ng-href using javascript: void(0);、angularjs – Angular sce.trustAsUrl和javascript hrefs、angularjs – 使用Thymeleaf 3 Beta的春季靴子、AngularJS 世界------Angularjs和Javascript以及表达式相关内容的相关知识,希望对你有所帮助。

本文目录一览:

javascript – Thymeleaf值发送angularJS ng-onclick方法(angular发送http请求)

javascript – Thymeleaf值发送angularJS ng-onclick方法(angular发送http请求)

我的问题是thymeleaf与angularJS的整合.我有这个thymleaf页面:

dam1.jpg" alt="" width="52" height="52" /> heading"> timageData()}" alt="" width="160" height="120"/>

我的AngularJS方法:

app.controller('ctrlsubcomment',function($scope,$http) {
    $scope.newssubcomment = {
        mainComment: { id : ""},comment: {text: ""}
    };

    $scope.addSubComment = function(commentId) {
        $scope.newssubcomment.mainComment.id = commentId;
        alert("helllo comment : "+commentId +" " + $scope.newssubcomment.mainComment.id);
    };
} 

我的代码不起作用.我有AngularJS语法错误:

“Error: Syntax Error: Token ‘{‘ is unexpected,expecting []] at column 17 of the expression [addSubComment([${newsComment.comment.id}])] starting at [{newsComment.comment.id}])].

最佳答案
我挖了所有互联网然后找到了解决方案.

th:attr="ng-click='addSubComment(\''+${newsComment.comment.id}+'\');'" 

引用:
http://www.mattheye.com/passing-data-between-spring-mvc-and-angularjs/

angularjs unsafe ng-href using javascript: void(0);

angularjs unsafe ng-href using javascript: void(0);

一、在AngularJs的页面中,如果使用数据绑定生成链接,默认会添加'unsafe:'标识,

对于页面定义好的不会添加。

1.页面定义的javascript:void(0);可以使用

<a href="javascript:open2('abc')">abc</a>

2.对于数据绑定的链接或者使用ng-href产生的链接,默认会添加un-safe
<div>
    <div>生成链接</div>
    <div>
        <div>
            <divng-repeat="item in items">
                <a href="{{item.link}}">{{item.name}}</a>
            </div>
        </div>
    </div>
</div>
(function() {
    'use strict';
    var app= angular.module('module',[
    ]);
    app.controller('myCtrl',function($scope){
    $scope.items=[
        {name:'百度',link:'javascript:void(0)'},{name:'工具集',link:'javascript:open(3)'}
    ];
    });
    window.open2=function(url){
        alert(url);
    }
})();
页面结果:



解决方案:在模块配置中,修改默认支持的协议javascript

angular.module('app').config( [
    '$compileProvider',function( $compileProvider )
    {   
        $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|sms):/);
        // Angular v1.2 之前使用 $compileProvider.urlSanitizationWhitelist(...)
    }
]);

更多:

AngularJS阻止事件冒泡$event.stopPropagation()

AngularJs select绑定数字类型问题

AngularJS路由之ui-router(三)大小写处理

angularjs – Angular sce.trustAsUrl和javascript hrefs

angularjs – Angular sce.trustAsUrl和javascript hrefs

我正在尝试创建一个具有书签的页面,如下所示:

<a ng-href="{{getBookmarklet()}}">Bookmarklet</a>

function MyCtrl($scope) {
  $scope.getBookmarklet = function() {
     return 'javascript:alert(1)';
  }
}

href被清理为不安全:javascript:alert(1).所以,我尝试过使用sce.trustAs来防止这种情况:

function MyCtrl($scope,$sce) {
  $scope.getBookmarklet = function() {
     return $sce.trustAsUrl('javascript:alert(1)');
  }
}

但是,我仍然在我的网址上获得“不安全”前缀.我也尝试过trustAsJs,没有运气.我不想在我的应用程序中使用compileProvider将javascript:URL列入白名单,只需允许这一个实例.

解决方法

我遇到了这个问题,并且能够通过使用$sce.trustAsHtml()来解决它.

JS:

function MyCtrl($scope,$sce) {
  $scope.getBookmarklet = function() {
    return $sce.trustAsHtml('<a href="javascript:alert(1)">Bookmarklet</a>');
  }
}

HTML:

<ng-bind-html ng-bind-html="::getBookmarklet()"></ng-bind-html>

这可能会引起CSS和其他指令的问题,但这些问题通常可以解决.

angularjs – 使用Thymeleaf 3 Beta的春季靴子

angularjs – 使用Thymeleaf 3 Beta的春季靴子

Thymeleaf 3 beta的弹簧启动似乎不太好.

java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration due to internal class not found. 

This can happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)

….

Caused by: java.lang.NoClassDefFoundError: org/thymeleaf/resourceresolver/IResourceResolver

有关如何使其工作的任何想法?

基本上,我有预先构建的HTML模板,它们并不真正符合XHTML标准,我想在Thymeleaf中使用它. Thymeleaf 2不支持HTML,甚至LEGACYHTML5模式因角度标记而引发错误

所以,我坚持使用只使用Thyme2而不支持Thyme3的Spring Boot,但我的应用程序只适用于Thyme3

解决方法

更新:从1.4开始,Spring Boot支持Thymeleaf 3但版本2仍然是默认值.有关如何使用Thymeleaf 3的详细信息,请参阅 the documentation.

Spring Boot 1.3及更早版本不支持Thymeleaf 3.您需要为Thymeleaf禁用Boot的自动配置并手动配置它.您可以使用exclude attribute on @SpringBootApplication禁用自动配置:

@SpringBootApplication(exclude=org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration.class)

AngularJS 世界------Angularjs和Javascript以及表达式相关内容

AngularJS 世界------Angularjs和Javascript以及表达式相关内容

在上节我们讲了Angular简介,其中最后说了有 表达式 、指令和模型。
下面三节将依次详细说一下。首先是表达式,那么Angular和Javascrit中的表达式有什么区别呢?

AngularJS 表达式

AngularJS 表达式写在双大括号内:{{ expression }}。
AngularJS 表达式把数据绑定到 HTML,这与 ng-bind 指令有异曲同工之妙。
AngularJS 将在表达式书写的位置”输出”数据。
AngularJS 表达式 很像 JavaScript 表达式:它们可以包含文字、运算符和变量。
实例 {{ 1 + 1 }} 或 {{ a+ ” ” + b }}

<!DOCTYPE html> <html> <head> <Meta charset="utf-8"> <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body> <div ng-app=""> <p>我的第一个表达式: {{ 1 + 1 }}</p> </div> </body> </html>

AngularJS 表达式 与 JavaScript 表达式

类似于 JavaScript 表达式,AngularJS 表达式可以包含字母,操作符,变量。
与 JavaScript 表达式不同,AngularJS 表达式可以写在 HTML 中。
与 JavaScript 表达式不同,AngularJS 表达式不支持条件判断,循环及异常。
与 JavaScript 表达式不同,AngularJS 表达式支持过滤器。

还有AngularJS和JavaScript 中的数字、字符串、对象、数组很像。

数字

<div ng-app="" ng-init="num=2;price=8"> <p>总价: {{ num * price }}</p> </div>

字符串

<div ng-app="" ng-init="a='aaa';b='bbb'"> <p>姓名: {{ a + " " + b }}</p> </div>

对象

<div ng-app="" ng-init="obj={a:'aaa',b:'bbb'}"> <p>姓为 {{ obj.a}}</p> </div>

数组

<div ng-app="" ng-init="arr=[0,1,2,3]"> <p>第三个值为 {{ arr[1] }}</p> </div>

今天关于javascript – Thymeleaf值发送angularJS ng-onclick方法angular发送http请求的分享就到这里,希望大家有所收获,若想了解更多关于angularjs unsafe ng-href using javascript: void(0);、angularjs – Angular sce.trustAsUrl和javascript hrefs、angularjs – 使用Thymeleaf 3 Beta的春季靴子、AngularJS 世界------Angularjs和Javascript以及表达式相关内容等相关知识,可以在本站进行查询。

本文标签:

上一篇spring – java.lang.IllegalStateException:SockJsMessageCodec是必需的但不可用:(sockjs报错)

下一篇Spring Boot Actuator相当打印JSON(springboot打印http请求)