Monday, March 2, 2015

Golang Template with AngularJS

If you get those errors while trying to make your templates with AngularJS, the fix is configuring AngularJS as shown below:

 angular.module("MyApp", []).config(["$interpolateProvider", function($interpolateProvider){
                $interpolateProvider.startSymbol("~{");
                $interpolateProvider.endSymbol("}~");
           }])


Using the $interpolateProvider, our frontent can now bind as shown below:

 <span>Date: ~{andate}~</span>

Instead of the double curlies "{{}}" we can now use "~{}~".


See also: http://golang.org/pkg/html/template/#Template.Delims