Home > front end >  I want to implement a search content, then automatically match the title of the relevant content and
I want to implement a search content, then automatically match the title of the relevant content and

Time:09-21

I want to implement a search content, then automatically match the title of the relevant content and content information,
<body ng - controller="CTR & gt;"


  • {{item. The title}}










<script>
Presents the module (" app ", [" ngSanitize "])
Controller (" CTR, "[" $scope", "$HTTP", "$rootScope", the function ($scope, $HTTP, $rootScope) {
$rootScope. NewsList=[
Cn: {en: "auto", "car", the state: true},
Cn: {en: "dy", "recommended", the state: true},
Cn: {en: "ent", "entertainment", the state: true},
Cn: {en: "home", "home", the state: true},
Cn: {en: "sports", "sports", the state: true},
Cn: {en: "tech", "science and education", the state: true},
Cn: {en: "toutiao," "news," the state: true},
Cn: {en: "war", "military", the state: true},
Cn: {en: "money", "financial", the state: false}
];
$rootScope. Activeitem="toutiao";
$scope. Newsname={" name ":" "};
Var url="yaowen. Json";
$scope. The getNews=function () {
HTTP (${
Methon: "GET",
Url: the url
{}). Then (function (res)
$rootScope.newsData=https://bbs.csdn.net/topics/res.data.data;

}),
Function (err) {
}
};

$scope. $watch (" Newsname ", function (n, o) {
For (var index in $rootScope. NewsData) {
for(var i=0; i<$rootScope. NewsData [index]. Length; I++) {
If (n.n ame==$rootScope. NewsData [index] [I] title) {
$scope. Newscn=$rootScope. NewsData [index] [I] the category;


}
}
The console. The log ($rootScope. NewsData [index] [I] the category)
}

});
$scope. The getNews ();


}])
</script>
  • Related