这不是我过去所知道的角度,而且我不知道在哪里可以模仿一个很好的例子,所以请您寻求帮助。
我想更新此页面的右侧部分,而无需使用ES2015 + angularJS + Webpack框架刷新页面。
我想要不同的控制器,现在页面上有一个控制器作为“ home”。当用户单击左侧时,我想更新其右侧部分,并为右侧部分使用单独的控制器。
我所知道的是,我只能写ng-controller = ...
,但是使用ES2015和webpack时,我开始感到困惑。
这就是我目前所拥有的。
首先,index.html
<html ng-app="abc" ng-strict-di>
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>{%= o.htmlWebpackPlugin.options.title %}</title>
</head>
<body>
<div class="container" ui-view></div>
</body>
</html>
然后是router.js
import HomeController from './home';
export default function routes($stateProvider) {
'ngInject';
$stateProvider
.state('home', {
url: '/',
template: require('./home.html'),
controller: HomeController,
controllerAs: 'home',
})
.state('android', {
url: '/android',
template: '<h2>This is Android</h2>',
parent: 'home'
});
}'
在这里发问,这个
'export default function routers($stateProvider) {}'
不是我知道的写角度的方式,有人可以在这里解释一下吗?这就是我定义HomeController的方式,我想遵循标准并为页面的右侧部分创建其他控制器。
export default class HomeController {
constructor($http) {
'ngInject';
this.currentPlatform = '';
this.platforms = [
{
displayName: "WEB PORTAL",
value : "WEB PORTAL"
},
{
displayName: "ROKU",
value : "ROKU"
},
{
displayName: "Android",
value : "ANDROID"
},
{
displayName: "iPhone",
value : "iPhone"
}
];
this.$http = $http;
this.projectName = "";
this.appId = "";
this.version = "";
this.fieldData = "";
}
}
另外,我还必须向您展示home.html,以便您可以据此给我说明。
<div class="home">
<div class="title">
<h1 class="h3">Build/Configure Apps</h1>
<span class="glyphicon glyphicon-remove"></span>
</div>
<div class="main">
<div class="row">
<div class="col-sm-4">
<ul class="nav nav-pills nav-stacked">
<li role="presentation" ng-repeat="platform in home.platforms" ng-class="{active: home.isSelected(platform.value)}">
<a ng-click="home.setPlatform(platform.value)">{{platform.displayName}}</a>
</li>
</ul>
<div class="form-inline form-group">
<div class="form-group">
<label for="appId" class="control-label">App Id:</label>
<input type="text" name="appId" ng-model="home.appId" class="form-control">
</div>
</div>
<div class="form-group">
<button type="button" name="button" class="btn btn-sm btn-primary col-sm-8" ng-click="home.makeAjaxCall()">Submit</button>
</div>
</div>
<div class="col-sm-8">
<h2>This right content should be updated when click on the left nav bar, but the left should not</h2>
</div>
</div>
</div>
</div>
提前致谢!
最佳答案
您的问题在这里相当笼统,但由于我知道背景,因此可以详细回答。
您的第一个问题:
导出默认功能路由器($ stateProvider){}
这就是ES6 + angular-ui-router-您应该使用UI-Router特定的路由来定义状态。
为了实现您的设计,您需要将static/index.html
更改为:
<body>
<div class="container">
<div ui-view="navbar">
</div>
<div ui-view></div>
</div>
</body>
并在stateprovider中定义一个navbar视图,以指向navbar.html,其中将包含:
<ul class="nav nav-pills nav-stacked">
<li role="presentation" ng-repeat="platform in home.platforms" ng-class="{active: home.isSelected(platform.value)}">
<a ng-click="home.setPlatform(platform.value)">{{platform.displayName}}</a>
</li>
</ul>
`
$stateProvider
.state('navbar', {
template: require('./navbar.html'),
controller: NavbarController,
controllerAs: 'navbar',
})
这应该使您入门。
关于javascript - 如何使用带有angular-webpack-seed的ES6语法更新部分HTML,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35070169/