我一直试图改变Angular的语法,所以我可以将它用于Handlebars,但它似乎并没有起作用。我认为它可以看到//demo.label//
因为它似乎没有在网页上显示它,但它也没有将示例文本放在标签内。对我所做错的任何帮助都将不胜感激。
<script>
var customInterpolationApp = angular.module('customInterpolationApp', []);
customInterpolationApp.config(function($interpolateProvider) {
$interpolateProvider.startSymbol('//');
$interpolateProvider.endSymbol('//');
});
customInterpolationApp.controller('DemoController', function() {
this.label = "This binding is brought you by // interpolation symbols.";
});
</script>
<div ng-app="customInterpolationApp" ng-controller="DemoController">
//demo.label//
</div>
答案 0 :(得分:1)
您没有在html中使用controller as
语法。您还必须定义控制器的别名,例如:ng-controller="DemoController as demo"
<强>演示:强>
var customInterpolationApp = angular.module('customInterpolationApp', []);
customInterpolationApp.config(function($interpolateProvider) {
$interpolateProvider.startSymbol('//');
$interpolateProvider.endSymbol('//');
});
customInterpolationApp.controller('DemoController', function() {
this.label = "This binding is brought you by // interpolation symbols.";
});
<script src="https://code.angularjs.org/1.5.2/angular.js"></script>
<div ng-app="customInterpolationApp" ng-controller="DemoController as demo">
//demo.label//
</div>