我的ng include不起作用
my ng-include does not work
我是AngularJS的新手。我正在尝试使用ng-include,但它没有显示我引用的html文件。
app.js代码
var app = angular.module('myApp', []);
app.controller('mainCtrl', [$scope, function($scope)
{
$scope.templateID = 'testing1.html';
$scope.changeTemplateID = function($scope){
$scope.templateID = 'testing2.html';
}
}]);
index.html文件
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script data-require="angularjs@1.5.0" data-semver="1.5.0" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.js"></script>
<link href="style.css" rel="stylesheet" />
<script src="script.js"></script>
</head>
<body ng-controller="mainCtrl">
<ng-include src="templateID"></ng-include>
<h1>Hello Plunker!</h1>
<p ng-click="changeTemplateID()">next</p>
</body>
</html>
根目录中有两个html文件。它们被称为testing1.html和testing2.html.我甚至试图像ng-include中的"'testing1.html"那样直接引用它们。
但没有成功。有什么帮助吗?
JS代码中的两个错误:
var app = angular.module('myApp', []);
// vvvvvvvv must be a string
app.controller('mainCtrl', ['$scope', function($scope)
{
$scope.templateID = 'testing1.html';
// you don't need to pass $scope here:
$scope.changeTemplateID = function(){
$scope.templateID = 'testing2.html';
}
}]);
Plunker供您细读。
app.controller('mainCtrl', [$scope, function($scope)...
你的[$scope
必须像字符串一样是['$scope'
,改变它就会好起来)
相关文章:
- AngularJS ng include dons'不起作用
- AngularJS ng include won'不知什么原因不起作用
- 如果在include文件中使用连接,Jquery ajax调用将不起作用
- ng-class 在 angularJs 中由 ng-include 包含的文件内不起作用
- 为什么我的jQuery Mobile include显然不起作用
- 我的ng include不起作用
- AngularJs ng-include src =“sample.html ” 不起作用
- ng-include in ng-table 不起作用
- rails bootstrap Javascript include 不起作用
- Angularjs data-ng-include 不起作用
- 为什么ng-include不起作用
- ng-click在引导的ng-include中不起作用
- jQuery's include方法不'不起作用
- AngularJS:嵌套控制器在ng-include中不起作用
- 当使用ng-include构建树时,我的'ng-click'不起作用
- AngularJs: ng-include在放置在ng-view标签中时不起作用
- 使用ng-include和ng-repeat的递归在第一级之后就不起作用了
- Angularjs的ng-include指令不起作用
- AngularJS中,ng-include不起作用
- JS Include不起作用