admin管理员组文章数量:1415145
I'm trying to load pages dynamically into a div
using a select
My HTML code :
<div ng-app="App" ng-controller="ProjectCtrl">
<div>
<select ng-model="selectedType" class="form-control" ng-change="showContent()" ng-options="type as type.text for type in types"></select>
</div>
<div>
<div ng-include src='getView()'></div>
</div>
</div>
My JS code :
$scope.showContent= function() {
$scope.getView = function() {
return $scope.selectedType.value ;
}
}
I got this error :
Error: [ng:areq] .2.2/ng/areq?p0=Ctrl&p1=not%20a%20function%2C%20got%20undefined
P.S: My views use angularJS too, and the idea is to get my page(View) from the select
.
"Ctrl" is the control name of the loaded page
I'm trying to load pages dynamically into a div
using a select
My HTML code :
<div ng-app="App" ng-controller="ProjectCtrl">
<div>
<select ng-model="selectedType" class="form-control" ng-change="showContent()" ng-options="type as type.text for type in types"></select>
</div>
<div>
<div ng-include src='getView()'></div>
</div>
</div>
My JS code :
$scope.showContent= function() {
$scope.getView = function() {
return $scope.selectedType.value ;
}
}
I got this error :
Error: [ng:areq] http://errors.angularjs/1.2.2/ng/areq?p0=Ctrl&p1=not%20a%20function%2C%20got%20undefined
P.S: My views use angularJS too, and the idea is to get my page(View) from the select
.
"Ctrl" is the control name of the loaded page
- Are you missing a } for the $scope.getView function? – Mike P Commented Feb 25, 2014 at 19:43
-
What's the
types
model look like? – Jonathan Rowny Commented Feb 25, 2014 at 19:43 -
Firstly have you considered using the Angular
$routeProvider
with theng-view
directive? If you are however set on this implementation or are usingngview
for something else: Can you give your full controller, and why is thegetView()
function nested in another function? – caffeinated.tech Commented Feb 25, 2014 at 19:44 - I found a way to reproduce this probem : plnkr.co/edit/zBagAdBgJlslULlKnkvW?p=preview (When you select url1 the example is broken and you got this error : Error: [ng:areq] errors.angularjs/1.2.13/ng/…) – Mils Commented Feb 25, 2014 at 22:08
2 Answers
Reset to default 2src
must evaluate to a String value, representing the URL to be included.
Still, your code is messy. You can:
- remove
showContent
listener at all - remove
getView
function and leave the expressionselectedType.value
selectedType.value
must be a string, representing the URL
See here: http://jsfiddle/E9rH4/1/
Watch the console error (see the url it tries to fetch).
Looks like $scope.selectedType.value is returning null. Try console.log
ging $scope.selectedType to see what you get. The function should return the full path.
Update After reviewing the plnk, it appears that you're trying to load an entire Angular app via ng-include. That's not what ng-include does, it just includes small templates. Here is the working plnkr
本文标签: javascriptLoading dynamically pages into div using angularJSStack Overflow
版权声明:本文标题:javascript - Loading dynamically pages into div using angularJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745211226a2647898.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论