我正在使用angularjs
parse
方法进行简单测试。我没有从测试中得到正确的输出。
这是我的角度代码:
var parseApp = angular.module('parse',[]);
parseApp.controller('parseController', ['$scope','$parse', function($scope,$parse){
$scope.parsedValue = "Testing";
$scope.$watch('expr',function(newVal,oldVal,scope){
if(newVal !== oldVal){
var parseFun = $parse(newVal);
$scope.parsedValue = parseFun(scope);
}
});
}])
html是这样的:
<div ng-app="parse">
<div ng-controller="parseController">
<input ng-model="expr"type="text" placeholder="Enter an expression" />
<h2>{{ parsedValue }}</h2>
</div>
</div>
收到错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module parse due to:
Error: [$injector:nomod] Module 'parse' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify th...<omitted>...0)
任何人请弄清楚我在这里做错了吗?
答案 0 :(得分:1)
解析是Angular中的一个保留字,因为它有一个名为$parse的服务,你需要有一个不同的名字,我的小提琴手里有parse1而且它有用
代码:
var parseApp = angular.module('parse1',[]);